开发者

Date : Converting AM to PM, and PM to AM

Perhaps a stupid question, but i really dont know the answer :(

lets s开发者_如何学Pythonay i have a date object, how can i change its AM date to PM, or vice verca?

Thanks


seems like you can

var currentTime = new Date();
var hours:uint = currentTime.getHours(); 

then you can say, if hours is greater than or equal to 12, then subtract by 12, otherwise, add 12 to it, for example, by

public static const millisecondsPerHour:int = 1000 * 60 * 60; 
var reversedAMPM = new Date(currentTime.getTime() + (12 * millisecondsPerHour));


Although Jian's version should work, here's an alternative.
Assuming var date:Date is initialized, you may literally change it:

date.hours += (date.hours > 12) ? -12:12;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜