PDA

View Full Version : date with string contstructor


kentyler
04-16-2003, 12:45 PM
when I run
var a = new Date(); // current date and time
debug.write( a );
I get Wed Apr 16 13:40:35 GMT-0700 2003
If I try
var b = newDate('Wed Apr 16 13:40:35 GMT-0700 2003')
debug.write( b );
I get invalid date.
My books says "The ECMAScript standard does not specify the format of the strings that can be parsed by date.parse()" and that when Date() is used with a string constructor it should be passed "a string reresentation of a date, in the format accepted by the Date.parse() method.

Do you know which string formats should work in Laszlo ?

antun
04-16-2003, 12:55 PM
You can either use the number of milliseconds from 1st Jan 1970 as an integer, or give it a number of comma-separated arguments:

year, month, [day], [hours], [minutes], [seconds], [milliseconds]

Square brackets are optional, but you can use it without any arguments to get the current date.

-Antun

kentyler
04-16-2003, 01:26 PM
That varies then, because the standard specifies that "this method can parse the strings returned by the Date.toString() and Date.toUTCString() methods.

if I do
var a = new Date();
var astring = a.toString();
var b = newDate(astring);
debug.write( b );

I get invalid date

the debug.write line is causing the error, if I comment it out the error is not reported. It causes the same error if I use
debug.write( b.toString() );

kentyler
05-03-2003, 03:22 PM
I went back today to working on dates and I am trying the static method Date.parse(dateasstring). Which does not seem to be implmented ?

antun
05-03-2003, 03:43 PM
That's right, I don't think Date.parse( str ) is implemented.

-Antun