On the experience of date conversion in asp.net

Source: Internet
Author: User
Tags date datetime tostring
Asp.net| Date | experience | Conversion date to a string is almost always the work of every project, no matter what development tool you use. Using convert or cast in SQL Server makes it easy to convert dates into strings of various formats, in which a string (date, "Yyyy-mm-dd") can be used in a single step. In the asp.net? I find that always less than I would, if using yyyy-mm-dd this way to convert:
BeginDate.SelectedDate.ToString ("Yyyy-mm-dd", Datetimeformatinfo.invariantinfo)
  
So get to be: 2004-00-23
  
Why is it 00? I can't think of a solution. To that end, I looked carefully at the help. The following code comes from the ASP.net online help.
  
The following example shows different ways to format a DateTime value with invariants DateTimeFormatInfo.
[Visual Basic]
Option Explicit
Option Strict
  
Imports System
Imports System.Globalization
  
Public Class MainClass
  
Public Shared Sub Main ()
Dim dt as DateTime = DateTime.Now
Dim MyFormat () as String = {"D", "D", _
"F", "F", _
"G", "G", _
"M", _
"R", _
"S", _
"T", "T", _
"U", "U", _
"Y", _
"dddd, MMMM dd yyyy", _
"DDD, MMM D" "" "yy", _
"dddd, MMMM dd", _
"M/yy", _
"Dd-mm-yy"}
Dim MyDate as String
Dim I as Integer
For i = 0 to MyFormat. Length-1
mydate = dt. ToString (MyFormat (i), datetimeformatinfo.invariantinfo)
Console.WriteLine (String.Concat (MyFormat (i), ":", MyDate))
Next I
  
' Output.
'
' d:08/17/2000
' D:thursday, August 17, 2000
' F:thursday, August 17, 2000 16:32
' F:thursday, August 17, 2000 16:32:32
' g:08/17/2000 16:32
' g:08/17/2000 16:32:32
' M:august 17
' R:thu, Aug 23:32:32 GMT
' S:2000-08-17t16:32:32
' T:16:32
' T:16:32:32
' U:2000-08-17 23:32:32z
' U:thursday, August 17, 2000 23:32:32
' Y:august, 2000
' dddd, MMMM DD Yyyy:thursday, August 17 2000
' DDD, MMM d ' ' Yy:thu, Aug 17 ' 00
' dddd, MMMM dd:thursday, August 17
' M/yy:8/00
' Dd-mm-yy:17-08-00
End Sub ' Main
End Class ' MainClass
  
Yes Ah, others write is also YYYY-MM-DD format, but people can return the result correctly, I can not. Slow down, I'll look again. Don't...... Is it the case? Yes, when ASP.net just released, it was announced that the case should be gradually referred to important position, completely change the size of the ASP era of confusion. In other words, the mm here to be written as mm can. I hold to try the psychological modification, pass, can successfully return to the 2004-08-23. This is not the end of knowledge, I immediately changed all to uppercase: YYYY-MM-DD, the result found that return YYYY-08-DD, that is, yyyy-mm-dd this way is the only available scenario.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.