简体   繁体   中英

How to convert “YYYY-MM-DDThh:mmTZD” to yyyy-MM-dd hh:mm:ss in C#

When I run this in C# in .net452,

DateTime myDateTime = Convert.TodateTime("2019-10-22T14:32:54.67685+01:00") 

on my rig I get eg 22/10/2019 14:32:54, but on my client pc, I'm seeing "2019-10-27 01:32:54".

How do I convert that string to a local date time on the PC?

This article tells you how to convert to that format, but I need the reverse.

Pointers please!

There are few ways to format the date.

Convert.ToDateTime("12/02/21 10:56:09").ToString("MMM.dd,yyyy HH:mm:ss");

Use DateTime.ParseExact, eg:

DateTime.ParseExact("12/02/21 10:56:09", "yy/MM/dd HH:mm:ss", 
    CultureInfo.InvariantCulture
    ).ToString("MMM. dd, yyyy HH:mm:ss")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM