Solved

How to create a date variable in Javascript?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now