Solved

How to create a date variable in Javascript?

Posted on 2008-06-14
2
494 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

696 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