开发者

Converting date to day of week

is there any ready to go so开发者_如何学Pythonlution within the microsoft framework, regarding conversion of date to day?

For example, i would like to convert this string 21/03/2010 (dd/mm/yyyy) to Sunday


Dim d = DateTime.Parse("21/03/2010").DayOfWeek()


This code will print Sunday on the console window

    Dim dateToShow as DateTime =  new DateTime(2010, 03,21)

    Console.WriteLine(dateToShow.DayOfWeek.ToString)


This should print "Sunday".

   string myDateTimeString = "21/03/2010";

   DateTime dt = DateTime.ParseExact(
        myDateTimeString, "dd/MM/yyyy", 
        new CultureInfo("en-Us", true)
        , DateTimeStyles.NoCurrentDateDefault);

   Console.WriteLine(dt.DayOfWeek);


I would use DateTime.TryParse() just to validate the user input.

Dim input As String = "2010/12/23"
Dim dateTime As DateTime
If DateTime.TryParse(input, dateTime) Then
    Console.WriteLine(dateTime.DayOfWeek)
Else
    Console.WriteLine("Invalid")
End If
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜