C # language is still more common, here we mainly introduce date-type data into C # Long integer data, including the introduction of DateTime constructors, and so on.
Why convert date-type data to C # Long integer data? There are many reasons for this, but personally, it is often used for the date store of the database. Since the definitions and processing of date types vary from one database to another, the definitions of date-type data are handled differently in various languages, because I would rather convert the date-type data into the database. Although you can also use strings to save, using strings can also involve many issues, such as zones, and it requires more space than saving C # Long integer data.
Date-type data, in C # 's participation in the operation, it should also be converted to long integer data to calculate. Its long value is the number that is represented by a 100-nanosecond interval of time since 12:00 midnight, January 1, 01. This number is called Ticks (scale) in the DateTime of C #. The DateTime type has a long, read-only property named Ticks that holds the value. Thus, it is very easy to get a long value from a datatime type of data, just read out the Ticks value of the Datatime object, such as:
long longDate = DateTime.Now.Ticks;
The DateTime constructor also provides a corresponding function to construct the datetime data from the Long Integer data: datetime (Long). Such as:
DateTime theDate = new DateTime(longDate);
But that's a problem for a lot of VB6 programmers, because the date-type data in VB6 is represented by a Double, which, when converted to a long integer, gets only the date, not the time. How do you reconcile both types of dates?
System.DateTime provides a double tooadate () and a static DateTime FromOADate (double) two functions to solve this problem. The former outputs the current object by the original double value, and the latter obtains a System.DateTime object from a double value. Examples are as follows:
private void TestDateTimeLong() {
double doubleDate = DateTime.Now.ToOADate();
DateTime theDate = DateTime.FromOADate(doubleDate);
this.textBox1.Text = "";
this.textBox1.AppendText("Double value of now: " + doubleDate.ToString() + "\n");
this.textBox1.AppendText("DateTime from double value: " + theDate.ToString() + "\n");
}
Run Result:
Double value of now: 37494.661541713
DateTime from double value: 2002-8-26 15:52:37