All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
datetime object

Path: /sdk/add_on/datetime/

The `CDateTime` class provides a way for scripts to get the system date and time.

Register the type with the `RegisterScriptDateTime(asIScriptEngine*)` function.

Note
  This class requires C++11 or later to compile.

# Public C++ interface

class CDateTime
{
public:
// Constructors
CDateTime();
CDateTime(const CDateTime &other);
CDateTime(asUINT year, asUINT month, asUINT day, asUINT hour, asUINT minute, asUINT second);
// Copy the stored value from another any object
CDateTime &operator=(const CDateTime &other);
// Accessors
asUINT getYear() const;
asUINT getMonth() const;
asUINT getDay() const;
asUINT getHour() const;
asUINT getMinute() const;
asUINT getSecond() const;
// Setters
// Returns true if valid
bool setDate(asUINT year, asUINT month, asUINT day);
bool setTime(asUINT hour, asUINT minute, asUINT second);
// Operators
// Return difference in seconds
asINT64 operator-(const CDateTime &other) const;
CDateTime operator+(asINT64 seconds) const;
friend CDateTime operator+(asINT64 seconds, const CDateTime &other);
CDateTime & operator+=(asINT64 seconds);
CDateTime operator-(asINT64 seconds) const;
friend CDateTime operator-(asINT64 seconds, const CDateTime &other);
CDateTime & operator-=(asINT64 seconds);
bool operator==(const CDateTime &other) const;
bool operator<(const CDateTime &other) const;
};

# Public script interface

      class datetime
      {
        datetime();
        datetime(const datetime &in other);
        datetime(uint y, uint m, uint d, uint h = 0, uint mi = 0, uint s = 0);

        datetime &opAssign(const datetime &in other);

        uint get_year() const;
        uint get_month() const;
        uint get_day() const;
        uint get_hour() const;
        uint get_minute() const;
        uint get_second() const;

        bool setDate(uint year, uint month, uint day);
        bool setTime(uint hour, uint minute, uint second);

        int64     opSub(const datetime &in) const;
        datetime  opAdd(int64 seconds) const;
        datetime  opAdd_r(int64 seconds) const;
        datetime &opAddAssign(int64 seconds);
        datetime  opSub(int64 seconds) const;
        datetime  opSub_r(int64 seconds) const;
        datetime &opSubAssign(int64 seconds);
        bool      opEquals(const datetime &in) const;
        int       opCmp(const datetime &in) const;
      }

## Constructors

datetime()
datetime(const datetime &in other)
datetime(uint y, uint m, uint d, uint h = 0, uint mi = 0, uint s = 0)

The default constructor initializes the object with the current system time.

The copy constructor copíes the content of the other object.

The set constructor initializes the object with the given date and time.

## Methods

uint get_year() const

Returns the year of the date stored in the object.

uint get_month() const

Returns the month of the date stored in the object. The range is 1 to 12, i.e. 1 is January, 12 is December, and so on.

uint get_day() const

Returns the day of the month of the date stored in the object.

uint get_hour() const

Returns the hour of the time stored in the object. The range is 0 to 23.

uint get_minute() const

Returns the minute of the time stored in the object. The range is 0 to 59.

uint get_second() const

Returns the second of the time stored in the object. The range is 0 to 59.

bool setDate(uint year, uint month, uint day)
bool setTime(uint hour, uint minute, uint second)

Sets the date or time. Returns true if the specified date or time is valid. Does not modify the object if not valid.

## Operators

= assignment

The assignment operator copies the content of the other object.

- difference

When subtracting one datetime object from another the result is the number of seconds between them.

+ add
- subtract
+= add assign
-= subtract assign

The datetime object can be added or subtracted with seconds to form a new datetime object.

==, != equality
<, <=, >=, > comparison

The datetime object can be compared for equality or relativity.