Altova XMLSpy 2024 Enterprise Edition

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

 

Constructors


Name

Description

ic_method

DateTime(DateTime obj)

Initializes a new instance of the DateTime class to the DateTime object supplied as argument.

ic_method

DateTime(System.DateTime newvalue)

Initializes a new instance of the DateTime class to the System.DateTime object supplied as argument.

ic_method

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

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

ic_method

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

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

ic_method

DateTime(int year, int month, int day)

Initializes a new instance of the DateTime class to the year, month and day supplied as arguments.

 

Properties


Name

Description

ic_property

bool HasTimezone

Gets a Boolean value which indicates if the DateTime has a timezone.

ic_property

static DateTime Now

Gets a DateTime object that is set to the current date and time on this computer.

ic_property

short TimezoneOffset

Gets or sets the timezone offset, in minutes, of the DateTime object.

ic_property

System.DateTime Value

Gets or sets the value of the DateTime object as a System.DateTime value.

 

Methods


Name

Description

ic_method

int CompareTo(object obj)

The DateTime class implements the IComparable interface. This method compares the current instance of DateTime to another object and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. See also https://msdn.microsoft.com/en-us/library/system.icomparable.compareto(v=vs.110).aspx

ic_method

override bool Equals(object obj)

Returns true if the specified object is equal to the current object; false otherwise.

ic_method

System.DateTime GetDateTime(bool correctTZ)

Returns a System.DateTime object from the current Altova.Types.DateTime instance. The correctTZ Boolean argument specifies whether the time of the returned object must be adjusted according to the timezone of the current Altova.Types.DateTime instance.

ic_method

override int GetHashCode()

Returns the hash code of the current instance.

ic_method

int GetWeekOfMonth()

Returns the number of the week in month as an integer.

ic_method

static DateTime Parse( string s )

Creates a DateTime object from the string supplied as argument. For example, the following sample string values would be converted successfully to a DateTime object:

 

2015-01-01T23:23:23

2015-01-01

2015-11

23:23:23

 

An exception is raised if the string cannot be converted to a DateTime object.

 
Note that this method is static and can only be called on the Altova.Types.DateTime class itself, not on an instance of the class.

ic_method

static DateTime Parse(string s, DateTimeFormat format)

Creates a DateTime object from a string, using the format supplied as argument. For the list of possible formats, see Altova.Types.DateTimeFormat.

 

An exception is raised if the string cannot be converted to a DateTime object.

 
Note that this method is static and can only be called on the Altova.Types.DateTime class itself, not on an instance of the class.

ic_method

override string ToString()

Converts the DateTime object to a string.

ic_method

string ToString(DateTimeFormat format)

Converts the DateTime object to a string, using the format supplied as argument. For the list of possible formats, see Altova.Types.DateTimeFormat.

 

Operators

Name

Description

!=

Determines if DateTime a is not equal to DateTime b.

<

Determines if DateTime a is less than DateTime b.

<=

Determines if DateTime a is less than or equal to DateTime b.

==

Determines if DateTime a is equal to DateTime b.

>

Determines if DateTime a is greater than DateTime b.

>=

Determines if DateTime a is greater than or equal to DateTime b.

 

Examples

Before using the following code listings in your program, ensure the Altova types are imported:

 

using Altova.Types;

 

The following code listing illustrates various ways to create DateTime objects:

 

protected static void DateTimeExample1()
{
  // Create a DateTime object from the current system time
  Altova.Types.DateTime dt = new Altova.Types.DateTime(System.DateTime.Now);
  Console.WriteLine("The current time is: " + dt.ToString());
           
  // Create an Altova DateTime object from parts (no timezone)
  Altova.Types.DateTime dt1 = new Altova.Types.DateTime(2015, 10, 12, 10, 50, 33);
  Console.WriteLine("My custom time is : " + dt1.ToString());
 
  // Create an Altova DateTime object from parts (with UTC+60 minutes timezone)
  Altova.Types.DateTime dt2 = new Altova.Types.DateTime(2015, 10, 12, 10, 50, 33, 60);
  Console.WriteLine("My custom time with timezone is : " + dt2.ToString());
 
  // Create an Altova DateTime object by parsing a string
  Altova.Types.DateTime dt3 = Altova.Types.DateTime.Parse("2015-01-01T23:23:23");
  Console.WriteLine("Time created from string: " + dt3.ToString());
 
  // Create an Altova DateTime object by parsing a string formatted as schema date
  Altova.Types.DateTime dt4 = Altova.Types.DateTime.Parse("2015-01-01", DateTimeFormat.W3_date);
  Console.WriteLine("Time created from string formatted as schema date: " + dt4.ToString());
}

 

The following code listing illustrates various ways to format DateTime objects:

 

protected static void DateTimeExample2()
{
  // Create a DateTime object from the current system time
  Altova.Types.DateTime dt = new Altova.Types.DateTime(System.DateTime.Now);
 
  // Output the unformatted DateTime
  Console.WriteLine("Unformatted time: " + dt.ToString());
 
  // Output this DateTime formatted using various formats
  Console.WriteLine("S_DateTime:       " + dt.ToString(DateTimeFormat.S_DateTime));
  Console.WriteLine("S_Days:           " + dt.ToString(DateTimeFormat.S_Days));
  Console.WriteLine("S_Seconds:        " + dt.ToString(DateTimeFormat.S_Seconds));
  Console.WriteLine("W3_date:          " + dt.ToString(DateTimeFormat.W3_date));
  Console.WriteLine("W3_dateTime:      " + dt.ToString(DateTimeFormat.W3_dateTime));
  Console.WriteLine("W3_gDay:          " + dt.ToString(DateTimeFormat.W3_gDay));
  Console.WriteLine("W3_gMonth:        " + dt.ToString(DateTimeFormat.W3_gMonth));
  Console.WriteLine("W3_gMonthDay:     " + dt.ToString(DateTimeFormat.W3_gMonthDay));
  Console.WriteLine("W3_gYear:         " + dt.ToString(DateTimeFormat.W3_gYear));
  Console.WriteLine("W3_gYearMonth:    " + dt.ToString(DateTimeFormat.W3_gYearMonth));
  Console.WriteLine("W3_time:          " + dt.ToString(DateTimeFormat.W3_time));
}

© 2018-2024 Altova GmbH