时区为 Venezuela Standard Time(-4:30)传回的时间如下
2016-04-20T06:02:13-04:4294967266
如何传成时间对象,直接convert会报错
未处理System.FormatException HResult=-2146233033 Message=String was not recognized as a valid DateTime. Source=mscorlib StackTrace: at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s) at InternalCrm.Test.TestTimeZone.Run() in c:Program.cs:line 82 at InternalCrm.Test.Program.Main(String[] args) in c:\Program.cs:line 198 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
string s = "2016-04-20T06:02:13-04:4294967266";
string fff = s.Substring(s.LastIndexOf(':') + 1);
s = s.Substring(0, s.LastIndexOf(':'));
s = s.Insert(19, "." + fff + " ");
DateTime d = DateTime.Parse(s);
这个做会少了30分错,
直接把 4294967266 替成30也是可以的,只是这样做看起来并不友好
@boron lin: 我还以为4294967266是毫秒呢
04:4294967266 保留到秒 四舍五入就可以了