VB. Date-time conversion in net
Just learn vb.net soon, in doing a few small examples when found often to the date time and the conversion between the string, now sorted as follows, if there is not the right place please point out.
1. Conversion between character type and date type
The conversion of date type to character type is the simplest and can be directly converted. Dim dt as Date = Now
Debug.WriteLine ("DT". tolongdatestring = "+ dt". tolongdatestring)
Debug.WriteLine ("DT". tolongtimestring = "+ dt". tolongtimestring)
Debug.WriteLine ("DT". toshortdatestring = "+ dt". toshortdatestring)
Debug.WriteLine ("DT". toshorttimestring = "+ dt". toshorttimestring)
Debug.WriteLine ("DT". Tofiletime = "+ dt". tofiletime.tostring)
Debug.WriteLine ("DT". TOFILETIMEUTC = "+ dt". tofiletimeutc.tostring)
Debug.WriteLine ("DT". ToLocalTime = "+ dt". tolocaltime.tostring)
Debug.WriteLine ("DT". ToOADate = "+ dt". tooadate.tostring)
Debug.WriteLine ("DT". ToUniversalTime = "+ dt". touniversaltime.tostring)
Debug.WriteLine ("DT". ToString = "+ dt". ToString)
Debug.WriteLine ("DT". ToString (yyyy/mm/dd hh:mm:ss:fff) = "+ dt". ToString ("Yyyy/mm/dd hh:mm:ss:fff"))
The results are as follows:
Dt. tolongdatestring = April 16, 2007
Dt. tolongtimestring = 15:10:21
Dt. toshortdatestring = 2007/04/16
Dt. toshorttimestring = 15:10
Dt. Tofiletime = 128211774217140929
Dt. TOFILETIMEUTC = 128211774217140929
Dt. ToLocalTime = 2007/04/16 15:10:21
Dt. ToOADate = 39188.6321957639
Dt. ToUniversalTime = 2007/04/16 6:10:21
Dt. ToString = 2007/04/16 15:10:21
Dt. ToString (yyyy/mm/dd hh:mm:ss:fff) = 2007/04/16 03:10:21:714
With DT. ToString ("Yyyy/mm/dd hh:mm:ss:fff") is the most convenient and can be converted to any desired string.
The millisecond portion of which has a maximum of 7 digits, "fff" means only the first three digits, and "fffffff" means to take all 7 bits.
The above example execution results found a strange problem in the execution of the result "DT". ToString = 2007/04/16 15:10:21 ",
and "dt." ToString (yyyy/mm/dd hh:mm:ss:fff) = 2007/04/16 03:10:21:714 ", the hours of the two difference by 12,
Many posts on the Internet are said to be due to the timing of the start of the problem, I think it must be the problem of conversion, otherwise why "ToString ()" is correct,
Estimate should be the problem of time, try to "ToString (" Yyyy/mm/dd HH:mm:ss:fff) "In the" HH "into the capital" HH ", execute OK. Dt. ToString (yyyy/mm/dd hh:mm:ss:fff) = 2007/04/16 03:13:13:884
Dt. ToString (yyyy/mm/dd HH:mm:ss:fff) = 2007/04/16 15:13:13:884
Especially noteworthy is the month "MM" and "MM", if the two write wrong is difficult to find. The case should note the place: year yyyy lowercase fixed
Month Month MM caps fixed
Day DD Lowercase Fixed
When Hour hh or HH case can be
minute Minute mm lowercase fixed
SEC Second SS Lowercase Fixed
Millisecond millisecond FF or FF capitalization (maximum 7 digits)
Dim dt as DateTime = Now
Debug.WriteLine ("DT". ToString (yyyy/mm/dd hh:mm:ss:fff) = "+ dt". ToString ("Yyyy/mm/dd hh:mm:ss:fff"))
Debug.WriteLine ("DT". ToString (yyyy/mm/dd hh:mm:ss:fffff) = "+ dt". ToString ("Yyyy/mm/dd hh:mm:ss:fffff"))
Debug.WriteLine ("DT". ToString (yyyy/mm/dd hh:mm:ss:fffffff) = "+ dt". ToString ("Yyyy/mm/dd hh:mm:ss:fffffff"))
Debug.WriteLine ("DT". ToString (yyyy/mm/dd HH:MM:SS:FFF) = "+ dt". ToString ("Yyyy/mm/dd HH:MM:SS:FFF"))
Debug.WriteLine ("DT". ToString (yyyy/mm/dd hh:mm:ss:fff) = "+ dt". ToString ("Yyyy/mm/dd hh:mm:ss:fff"))
The results are as follows:
Dt. ToString (yyyy/mm/dd hh:mm:ss:fff) = 2007/04/16 03:15:13:887
Dt. ToString (yyyy/mm/dd hh:mm:ss:fffff) = 2007/04/16 03:15:13:88783
Dt. ToString (yyyy/mm/dd hh:mm:ss:fffffff) = 2007/04/16 03:15:13:8878378
Dt. ToString (yyyy/mm/dd HH:MM:SS:FFF) = yyyy/04/