?
Solved

How to create a date variable in Javascript?

Posted on 2008-06-14
2
Medium Priority
?
497 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

801 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