Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
 Collapse AllExpand All        Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: JScript 
Date.parse Method (Windows Scripting - JScript)

Parses a string containing a date, and returns the number of milliseconds between that date and midnight, January 1, 1970.

Date.parse(dateVal) 

The required dateVal argument is either a string containing a date in a format such as "Jan 5, 1996 08:47:00" or a VT_DATE value retrieved from an ActiveX® object or other object.

The parse method returns an integer value representing the number of milliseconds between midnight, January 1, 1970 and the date supplied in dateVal.

The parse method is a static method of the Date object. Because it is a static method, it is invoked as shown in the following example, rather than invoked as a method of a created Date object.

var datestring = "November 1, 1997 10:15 AM";
Date.parse(datestring)

The following rules govern what the parse method can successfully parse:

  • Short dates can use either a "/" or "-" date separator, but must follow the month/day/year format, for example "7/20/96".

  • Long dates of the form "July 10 1995" can be given with the year, month, and day in any order, and the year in 2-digit or 4-digit form. If you use the 2-digit form, the year must be greater than or equal to 70.

  • Any text inside parentheses is treated as a comment. These parentheses may be nested.

  • Both commas and spaces are treated as delimiters. Multiple delimiters are permitted.

  • Month and day names must have two or more characters. Two character names that are not unique are resolved as the last match. For example, "Ju" is resolved as July, not June.

  • The stated day of the week is ignored if it is incorrect given the remainder of the supplied date. For example, "Tuesday November 9 1996" is accepted and parsed even though that date actually falls on a Friday. The resulting Date object contains "Friday November 9 1996".

  • JScript handles all standard time zones, as well as Universal Coordinated Time (UTC) and Greenwich Mean Time (GMT).

  • Hours, minutes, and seconds are separated by colons, although all need not be specified. "10:", "10:11", and "10:11:12" are all valid.

  • If the 24-hour clock is used, it is an error to specify "PM" for times later than 12 noon. For example, "23:15 PM" is an error.

  • A string containing an invalid date is an error. For example, a string containing two years or two months is an error.

The following example illustrates the use of the parse method. Provide the function with a date and the function will return the difference between the date provided and 1/1/1970:

function GetTimeTest(testdate){
   var s, t;                    //Declare variables.
   var MinMilli = 1000 * 60;       //Initialize variables.
   var HrMilli = MinMilli * 60;
   var DyMilli = HrMilli * 24;
   t = Date.parse(testdate);       //Parse testdate.
   s = "There are "                //Create return string.
   s += Math.round(Math.abs(t / DyMilli)) + " days "
   s += "between " + testdate + " and 1/1/70";
   return(s);                      //Return results.
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
2 digit years are assumed to be in 1900's!      ttulinsky   |   Edit   |   Show History
a date like "06/25/08" results in June 25 1908.

this code:
dtstr = "06/25/08 07:00PM";
var d = new Date(dtstr);
platform.echo("date string = "+dtstr+" msec ="+d.getTime()+" d = "+d);

produces this:
06/25/08 07:00PM msec =-1941314400000 d = Thu Jun 25 19:00:00 PDT 1908

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker