Convert DateTime to a specified Format

前端 未结 5 1085
长发绾君心
长发绾君心 2020-11-30 08:42

I have this date format yy/MM/dd HH:mm:ss ex: 12/02/21 10:56:09. The problem is, when i try to convert it to different format using this code:

相关标签:
5条回答
  • 2020-11-30 09:23

    Assuming that you are meaning to ask how to get VB to parse the date as yy/MM/dd, the answer is simple: just use DateTime.ParseExact("12/02/12 10:56:09", "yy/MM/dd HH:mm:ss") and then use ToString() as before.

    0 讨论(0)
  • 2020-11-30 09:31

    Use DateTime.ParseExact, e.g.:

    DateTime.ParseExact("12/02/21 10:56:09", "yy/MM/dd HH:mm:ss", 
        CultureInfo.InvariantCulture
        ).ToString("MMM. dd, yyyy HH:mm:ss")
    
    0 讨论(0)
  • 2020-11-30 09:38

    Even easier way to convert Date:

    Convert.ToDateTime("12/02/21 10:56:09").ToString("MMM.dd,yyyy HH:mm:ss");
    
    0 讨论(0)
  • 2020-11-30 09:38
    var dateTime = DateTime.ParseExact("12/02/21 10:56:09", "yy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
    
    var text = dateTime.ToString("MMM. dd, yyyy HH:mm:ss");
    
    0 讨论(0)
  • 2020-11-30 09:43

    Try this:

    DateTime.ParseExact("12/02/21 10:56:09", "yy/MM/dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("MMM. dd, yyyy HH:mm:ss");
    
    0 讨论(0)
提交回复
热议问题