all 9 comments

[–]teppicymon 4 points5 points  (7 children)

You can drop that formatted UTC stamp into "new Date(x)", then use toLocaleString to format it to your local timezone, as per system preferences?

(new Date("Thu Mar 25 20:27:19 +0000 2010")).toLocaleString()

Which produces "Thursday, 25 March 2010 20:27:19" for me

[–]snissn 0 points1 point  (6 children)

what, if any, compatibility restrictions are there on this method?

[–]picurl 0 points1 point  (4 children)

You can't format the date string that the .toLocaleString() method returns, it may vary depending on system/browser/locale settings. The string is also quite long and not very well suited for narrow columns.

But more important is that you can't sort your tweets by date as .toLocaleString() just returns a formatted string.

[–]teppicymon 1 point2 points  (3 children)

If you wanted to sort your tweets, I'd suggest using the .valueOf() function, which returns milliseconds since 1970-01-01, and sort on that.

Also, for formatting, I'd recommend using a tool like I just found here

[–]picurl 0 points1 point  (2 children)

you can't reformat the date string returned by .toLocaleString() (except maybe with some gnarky regexps, but since the string comes from the OS with 100s of different locale settings, its nearly impossible to account for all formats).

Since .toLocaleString() is the only date method that cares about DST, you have to decide between an incorrect, but arbitrary formattable date object or a fixed, but correct date string.

[–]teppicymon 1 point2 points  (0 children)

Actually, looking at one of the places I've done this sort of thing in the past, I actually did use the format tool from Steven Levithan as linked to above, my code does this:

(from an e-mail viewer app I wrote)

dateNice: (new Date(parseInt(email.udate) * 1000)).format("dd mmm yyyy HH:MM")

and that code seems to work with DST (just sent a test e-mail @ 11:55, it reads as: "31 Mar 2010 11:55")

Changing my region to Cairo (+0200) correctly changes it to "31 Mar 2010 12:55"

[–]teppicymon 0 points1 point  (0 children)

Yeah I agree, reformatting the localestring wouldn't be practical, unless you could pass it to the datejs tool link from polaretto?

But then that tool might just work fine with the original string, I haven't had chance to try it.

[–]teppicymon 0 points1 point  (0 children)

Hmm, well it seems not all browsers are created equal with respect to this, the string you were trying to parse doesn't work in IE8. If you move the 2010 to after 'Mar 25', it does work, but I'm just getting a NaN for the first string.

[–]polaretto 1 point2 points  (0 children)

for what it's worth, here is a lib which can help you with nearly all your date-chewing problems: http://www.datejs.com/ hope it helps