|Home | Tutorial | Classes | Functions | QSA Workbench | Language | Qt API | QSA Articles Qt Script for Applications

[Prev: Boolean] [Home] [Next: Function Type]

Date

Instances of the Date class are used to store and manipulate dates and times.

A variety of get functions are provided to obtain the date, time or relevant parts, for example, getDay(), getYear(), getHours(), getMilliseconds(), getMinutes(), getMonth(), getSeconds(), getTime().

A complementary set of functions are also provided, including setYear(), setHours(), setMilliseconds(), setMinutes(), setMonth(), setSeconds(), setTime().

The functions operate using local time.

Conversion between Date objects to and from strings are provided by parse() and Date::toString().

Elapsed time (in milliseconds) can be obtained by creating two dates, casting them to Number and subtracting one value from the other.

var date1 = new Date();
// time flies..
var date2 = new Date();
var timedifference = date2.getTime() - date1.getTime();
Static Date Functions
Date Construction
Date()
Date( milliseconds )
Date( year, month, day, optHour, optMinutes, optSeconds, optMilliseconds )

    var today = new Date();
    var d = new Date( 1234567 );
    var date = new Date( 1994, 4, 21 );
    var moment = new Date( 1968, 5, 11, 23, 55, 30 ); 

Dates can be constructed with no arguments, in which case the value is the date and time at the moment of construction using local time. A single integer argument is taken as the number of milliseconds since midnight on the 1st January 1970.

Date Functions