Altova MapForce 2025 Professional Edition

This class enables you to process XML attributes or elements that have date and time types, such as xs:dateTime.

 

Constructors

Name

Description

DateTime()

Initializes a new instance of the DateTime class to 12:00:00 midnight, January 1, 0001.

DateTime(__int64 value, short timezone)

Initializes a new instance of the DateTime class. The value parameter represents the number of ticks (100-nanosecond intervals) that have elapsed since 12:00:00 midnight, January 1, 0001.

DateTime(int year, unsigned char month, unsigned char day, unsigned char hour, unsigned char minute, double second)

Initializes a new instance of the DateTime class to the year, month, day, hour, minute, and second supplied as argument.

 

DateTime(int year, unsigned char month, unsigned char day, unsigned char hour, unsigned char minute, double second, short timezone)

Initializes a new instance of the DateTime class to the year, month, day, hour, minute, second and timezone supplied as argument. The timezone is expressed in minutes and can be positive or negative. For example, the  timezone "UTC-01:00" is expressed as "-60".

 

 

Methods

Name

Description

unsigned char Day() const

Returns the day of month of the current DateTime object. The return values range from 1 through 31.

int DayOfYear() const

Returns the day of year of the current DateTime object. The return values range from 1 through 366.

bool HasTimezone() const

Returns Boolean true if the current DateTime object has a timezone defined; false otherwise.

unsigned char Hour() const

Returns the hour of the current DateTime object. The return values range from 0 through 23.

static bool IsLeapYear(int year)

Returns Boolean true if the year of the DateTime class is a leap year; false otherwise.

unsigned char Minute() const

Returns the minute of the current DateTime object. The return values range from 0 through 59.

unsigned char Month() const

Returns the month of the current DateTime object. The return values range from 1 through 12.

__int64 NormalizedValue() const

Returns the value of the DateTime object expressed as the Coordinated Universal Time (UTC).

double Second() const

Returns the second of the current DateTime object. The return values range from 0 through 59.

void SetTimezone(short tz)

Sets the timezone of the current DateTime object to the timezone value supplied as argument. The tz argument is expressed in minutes and can be positive or negative.

short Timezone() const

Returns the timezone, in minutes, of the current DateTime object. Before using this method, make sure that the object actually has a timezone, by calling the HasTimezone() method.

__int64 Value() const

Returns the value of the DateTime object, expressed in the number of ticks (100-nanosecond intervals) that have elapsed since 12:00:00 midnight, January 1, 0001.

int Weekday() const

Returns the day of week of the current DateTime object, as an integer. Values range from 0 through 6, where 0 is Monday (ISO-8601).

int Weeknumber() const

Returns the number of week in the year of the current DateTime object. The return values are according to ISO-8601.

int WeekOfMonth() const

Returns the number of week in the month of the current DateTime object. The return values are according to ISO-8601.

int Year() const

Returns the year of the current DateTime object.

 

Example

void Example()
{
  // initialize a new DateTime instance to 12:00:00 midnight, January 1st, 0001
  altova::DateTime dt1 = altova::DateTime();
 
  // initialize a new DateTime instance using the year, month, day, hour, minute, and second
  altova::DateTime dt2 = altova::DateTime(2015, 11, 10, 9, 8, 7);
 
  // initialize a new DateTime instance using the year, month, day, hour, minute, second, and UTC +01:00 timezone
  altova::DateTime dt = altova::DateTime(2015, 11, 22, 13, 53, 7, 60);
   
  // Get the value of this DateTime object
  std::cout << "The number of ticks of the DateTime object is: " << dt.Value() << std::endl;
 
  // Get the year
  cout << "The year is: " << dt.Year() << endl;
  // Get the month  
  cout << "The month is: " << (int)dt.Month() << endl;
  // Get the day of the month
  cout << "The day of the month is: " << (int) dt.Day() << endl;
  // Get the day of the year
  cout << "The day of the year is: " << dt.DayOfYear() << endl;
  // Get the hour
  cout << "The hour is: " << (int) dt.Hour() << endl;
  // Get the minute
  cout << "The minute is: " << (int) dt.Minute() << endl;
  // Get the second
  cout << "The second is: " << dt.Second() << endl;
  // Get the weekday
  cout << "The weekday is: " << dt.Weekday() << endl;
  // Get the week number
  cout << "The week of year is: " << dt.Weeknumber() << endl;
  // Get the week in month
  cout << "The week of month is: " << dt.WeekOfMonth() << endl;
 
  // Check whether a DateTime instance has a timezone
  if (dt.HasTimezone() == TRUE)
  {      
    // output the value of the Timezone
    cout << "The timezone is: " << dt.Timezone() << endl;
  }
  else
  {
    cout << "No timezone has been defined." << endl;
  }
 
  // Construct a DateTime object with a timezone UTC+01:00 (Vienna)
  altova::DateTime vienna_dt = DateTime(2015, 11, 23, 14, 30, 59, +60);
  // Output the result in readable format
  cout << "The Vienna time: "
      << (int) vienna_dt.Month()
      << "-" << (int) vienna_dt.Day()
      << " " << (int) vienna_dt.Hour()
      << ":" << (int) vienna_dt.Minute()
      << ":" << (int) vienna_dt.Second()
      << endl;
 
  // Convert the value to UTC time
  DateTime utc_dt = DateTime(vienna_dt.NormalizedValue());
  // Output the result in readable format
  cout << "The UTC time:    "
    << (int) utc_dt.Month()
    << "-" << (int) utc_dt.Day()
    << " " << (int) utc_dt.Hour()
    << ":" << (int) utc_dt.Minute()
    << ":" << (int) utc_dt.Second()
    << endl;
 
  // Check if a year is a leap year
  int year = 2016;
  if( altova::DateTime::IsLeapYear(year) )
  { cout << year << " is a leap year" << endl; }
  else
  { cout << year << " is not a leap year" << endl; }  
}

© 2018-2024 Altova GmbH