Date

Example 1: New date object with no parameters

In this example, the variable myDate creates a new object with no parameters. Examples 2 and 3 below also create a date object but a specific date has been added. The date contained in the new object for Example 1 will be the current date and time on your computer

var myDate = new Date()

Example 2: New date set by entering milliseconds

In this example, the variable myDate creates a new date based on number of milliseconds you have entered. This is the number of milliseconds that have passed since Midnight 1/1/1970

var myDate = new Date(949278000000)

The date and time will be set to 31 January 2000 00:20:00

Example 3: New date set by entering a string

In this example the date is set by entering a string showing the date, month, year followed by the time in hours, minutes and seconds. You must enter the string in the same syntax as the example

var myDate = new Date("25 December 2001, 00:00:00")

Example 4: Using the Date object properties

When you have created a new date object, the object contains a list of properties that allow you to get sections of the date and store them to a variable or alternatively, you can set sections of the date to a new value. The full list of properties is available in Date section of this Help file – see Date Overview for more information.

var myDate = new Date()
var currHour = myDate.getHours()

In the example above, the variable currHour will contain the current hour e.g. the number 0 indicates midnight, 22 indicates 10pm and so on. In the example below, the setHours function is used to change the hours for the date object myTime, the new date is then stored in a variable showTime

var myTime = new Date()
var currTime = myTime.setHours(3)
var showTime = myDate

Close