Link to home
Start Free TrialLog in
Avatar of frankmorrison
frankmorrison

asked on

How to create a date variable in Javascript?

My database stores the "start date & time" of an event using the unix epoc format which is the number of milliseconds since midnight Jan 1, 1970.
For example, if an event is scheduled for Saturday June 14th 2008 @ 8AM Pacific Daylight Time then, the database will store "1213455600";
How do I tell Javascript to put this value into a date object?

<script language=javascript>
myDate = newDate('1213455600'); // I know this is wrong, but here's where I need help

</script>
Avatar of David S.
David S.
Flag of United States of America image

This isn't a homework question, is it?

Pass the milliseconds since the epoch.

There needs to be a space after the new operator.

It's best to always use the var keyword.

The language attribute of the <script> element is deprecated, so it's best to avoid using it. You should use  type="text/javascript"  instead.
<script type="text/javascript">
var myDate = new Date(1213455600000);
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial