Date Object

Top  Previous  Next

The date object provides a range of properties and functions to manipulate dates and times.

 

Properties

Methods

Operators

Properties

Name

Type

Description

year

number

The year

month

number

The month

day

number

The day

hour

number

The hour

minute

number

The minutes

second

number

The second

millisecond

number

The millisecond. Note that the date object does not have millisecond granularity.

Methods

Return

Signature

Flags

Time

time()

[const]


setTime( Time )


number

toTime_t()

[const]


setTime_t ( number )

 


addSeconds ( number )



addDays ( number )



addMonths ( number )



addYears ( number )


boolean

isValid ( )

[const]

number

secsTo ( Date )

[const]

number

daysTo ( Date )

[const]

Date

toLocal ( )

[const]

Date

toUtc ( )

[const]

boolean

isLocal ( )

[const]

Date::time()

[const] Returns the Time object for this Date object. Since the date object is really a Date-Time object. This does not change the object's value as it makes a copy of the time.

Date::setTime( Time )

Sets the Time object for the Date object.

Date::toTime_t()

[const] Returns the number of seconds since 1970 Jan 1 0:00 UTC.

Date::setTime_t(secondsSinceEpoch)

Sets the date object to the date that corresponds to seconds since 1970 Jan 1 0:00 UTC.

Date::addSeconds( seconds )

Adds seconds to the date value.

Date::addDays( days )

Adds days to the date value.

Date::addMonths( months )

Adds months to the date value.

Date::addYears( years )

Adds years to the date value.

Date::isValid()

[const] Returns true if the date is valid.

Date::secsTo( Date )

[const] Returns the number of seconds to the parameter Date object.

Date::daysTo( Date )

[const] Returns the number of days to the parameter Date object.

Date::toLocal()

[const] Returns a new Date object set to local time.

Date::toUtc()

[const] Returns a new Date object set to Utc time.

Date::isLocal()

[const] Returns true if the time is set to local time.

Operators

The date object has a few operators overloaded

 

Date::-Time

Date::-number

Date::+Time

Date::+number

Date::<,>,<=,>=,== Date

Date::- Time

Subtract time from date.

Date::- number

Subtract number of seconds from date

Date::+ Time

Add time to date.

Date::+ number

Add number of seconds to date.

Date::<, >, <=, >=, == Date

[const] The usual relational operators allowing for quick date comparisons.

Example

local localTime = date.now()

print(localTime)

localTime = localTime + 100

print(localTime)

 

 

Prints

 

Sun Oct 14 21:59:41 2012

Sun Oct 14 22:01:21 2012

 

Related

Time Object

Date functions