实体类属性:

public virtual ​DateTime? ​CompletionTime { get; set; }

使用: CompletionTime.ToString("yyyy-MM-dd HH:mm:ss");

 解决方法 : CompletionTime​?.​ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") ​?? ""​;

var dateInUTCString = date?.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'") ?? "";

OR

var dateInUTCString = date.HasValue ? date.Value.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'") : "";

参考:​​https://stackoverflow.com/questions/60540633/convert-datetime-to-string​


C# Convert DateTime? to string_解决方法

备注:UTC美冬时间,与北京时间相差8小时

C# Convert DateTime? to string_实体类_02