none
Convert String to DateTimeFormat RRS feed

  • Question

  • I have date format "2018-06-14T20:23:03.985+05:30" reading as string .I need to convert this string to datetime format.

    How can i convert using C#.

    Thanks in advance.

    Sunday, July 8, 2018 8:44 AM

All replies

  • string test = "2018-06-14T20:23:03.985+05:30";
    DateTime dt = DateTime.Parse(test);


    Sunday, July 8, 2018 9:16 AM
  • Hi SiddharthVaish,

    You could also try the following two methods.

    1. 

    string test = "2018-06-14T20:23:03.985+05:30";
    DateTime myDate = Convert.ToDateTime(test);

    2. 
    string test = "2018-06-14T20:23:03.985+05:30";
    DateTime dateTime;
    DateTime.TryParse(test, out dateTime);

    Best regards,

    zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 9, 2018 1:29 AM
    Moderator
  • HI,

    try below for different formats.

    Convert.ToDateTime(item.Value).ToString("dd-MMM-yyyy")

    Monday, July 9, 2018 9:03 AM