views:

51

answers:

2

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

lets say i have a date object, how can i change its AM date to PM, or vice verca?

Thanks

+3  A: 

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));
動靜能量
Thanks Jian Lin
Max
+2  A: 

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;
MrKishi
can literally change it? that's cool. one catch is, will hour of 24 work? (and will it go to next day?)
動靜能量
I'll behave just like adding or subtracting those milliseconds..
MrKishi
Thanks Kishi :)
Max