In comp.lang.javascript message <11**********************@p10g2000cwp.go
oglegroups.com>, Tue, 6 Mar 2007 08:24:03, "ma**@gaspdesign.co.uk"
<ma**@gaspdesign.co.ukposted:
>im trying to convert Date() into a unix timestamp so i can stick the
result into a mysql db, please help!
In Javascript, Date() gives a string, and of undefined format (ISO 16262
15.9.2 &c). It's not a good starting-point for most requirements.
But new Date() gives a Date Object, and so + new Date() gives
the number of milliseconds (ignoring Leap Seconds, but not Summer Time)
since the Javascript Epoch. Converting that to the number of seconds
since the UNIX Epoch can be left as an exercise.
If you want a MySQL format from a Javascript group, you should give its
definition. Does it require to be in UTC or in local, with/without
offset in what form? In any case, reading the newsgroup FAQ should put
you in the right direction.
If you require a string YYYYMMDDhhmmss, it's easiest to use, in a string
context, Y*1e10 + M*1e8 + D*1e6 + h*1e4 + m*1e2 + s*1e0 .
BTW, in the FAQ, it may become desirable to convert from ISBN-10 to the
current ISBN-13 : see <URL:http://www.merlyn.demon.co.uk/js-misc0.htm>.
It's a good idea to read the newsgroup and its FAQ. See below.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.