Closed nareshbhatia closed 11 years ago
toString takes in a format and a tz, both of which are optional. Default format is yyyy-MM-dd HH:mm:ss
. The tokens are:
y
: yeard
: datem
: minutes
: secondS
: millisecondM
: month. Note: MM
will be the numeric representation (e.g February is 02) but MMM
will be text representation (e.g February is Feb)k
: AM/PMH
: hourE
: dayZ
: timezone abbreviation@longlho, thanks so much for a quick response - this works like a charm!
A couple of follow up questions:
date.toString('dd MMM yyyy HH:mm Z')
was enough to get CDT/CST to be outputted correctly. There was no need to add the second parameter, since I assume the timezone was picked up from the date. I was able to override the output by adding a different timezone in the second parameter. Is this how the second parameter intended to work?Thanks again.
For the 1st question: yes that's indeed how it works.
For the 2nd question: The API is the exact replicate of the normal JS Date object since it's supposed to be just a wrapper. The toString
method (along with set
and get
timezone) are pretty much the only differences.
The API for tz parsing is in the README I believe.
Another curious question. In the constructor below, why do I have to supply the timezone in the second parameter even though it is included in the string? Seems limiting in case I need to read bunch of date strings with different time zones embedded in them.
new timezoneJS.Date('09 Mar 2008 01:00 CST', 'America/Chicago')
I am trying to output timezoneJS.Date in the same format that I receive it - with CST/CDT indicating the timezone (IETF-compliant RFC 2822 format). For example, here are two times on the day when Daylight Savings time began in 2008:
timezoneJS.Date constructor correctly parses the date, but I cannot figure out how to easily format the output to look exactly like the input. Also it appears that I must specify the 2nd parameter although the timezone is included in the input string.
The output is shown below, not in the input format and also no timezone string.
What is the easiest way to get the desired output?
Thanks.