Solved

How to create a date variable in Javascript?

Posted on 2008-06-14
2
493 Views
Last Modified: 2012-05-05
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>
0
Comment
Question by:frankmorrison
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Expert Comment

by:David S.
ID: 21786754
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

0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 21786755
Check this:
<script language=javascript>
myDate = new Date('1213455600'*1000); // I know this is right
 
alert(myDate);
</script>

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question