public class ChangeDateTimeKind { public static async Task ToUtc<T>(T model) { Type NewType = typeof(T); foreach (PropertyInfo item in NewType.GetRuntimeProperties()) { string Name = item.PropertyType.Name; if (Name.ToLower()=="datetime") { await Task.Run(() => { DateTime getDateTime = Convert.ToDateTime(item.GetValue(model, null)); object v = Convert.ChangeType(DateTime.SpecifyKind(getDateTime, DateTimeKind.Utc), item.PropertyType); item.SetValue(model, v, null); }); } } } }
标签:getDateTime,Name,item,自动,小时,model,null,NewType,Mongo From: https://www.cnblogs.com/MakeGod/p/16804981.html