Our previous developer create a generic method that retrieve all user input that has an update/changes. it looks like this (user side/JavaScript/Kendo):
我们以前的开发人员创建了一个通用方法,用于检索具有更新/更改的所有用户输入。它看起来像这样(用户端/ JavaScript / Kendo):
param._updated = JSON.stringify(rows._updated);
I am somehow desperate that when that *rows._updated contains a Date Value uncle JSON convert it into other String format that result to DateTime Difference for example:
我在某种程度上绝望,当* rows._updated包含日期值时,叔叔JSON将其转换为其他String格式,导致DateTime差异,例如:
dateField = 11/1/2015 // <--Original User Input
rows._updated = { dateField: November 1, 2015 0:00:00 GMT+080 ... }
param._updated = { "dateField": "2015-10-31T16:00:00.0000Z"... }
which would now result to a conflict. since the above code was generic field that might contain different data and type, I am trying to solve this issues at the server side but i failed to achieve the original date value.
这将导致冲突。由于上面的代码是可能包含不同数据和类型的通用字段,我试图在服务器端解决这个问题,但我没有达到原始日期值。
NOTE: our users has 2-5 different timezone so it's kinda hard to hard code the conversion. related issues: here
注意:我们的用户有2-5个不同的时区,因此很难对转换进行硬编码。相关问题:这里
It's getting late. Thanks in advance!.
天色已晚。提前致谢!。
1 个解决方案
#1
0
I somehow achieve what I want to by the following approach
我通过以下方法实现了我想要的目标
1.) At backend Convert the DateTime to UTC Format
1.)在后端将DateTime转换为UTC格式
string dateUTC = paramDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
2.) Now I have created a method that will handle the convertion of UTC Date to PlainDate
2.)现在我已经创建了一个方法来处理UTC Date转换为PlainDate
public static string UTCtoPlainDate(string dateUTC)
{
if (string.IsNullOrEmpty(dateUTC)) return "";
DateTime dateTime;
// Assume date in UTC format, e.g. '2015-03-31T12:00:00.000Z'
DateTime.TryParseExact(dateUTC, "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.AssumeUniversal, out dateTime);
return dateTime.ToString("yyyy-MM-dd") ?? "";
}
#1
0
I somehow achieve what I want to by the following approach
我通过以下方法实现了我想要的目标
1.) At backend Convert the DateTime to UTC Format
1.)在后端将DateTime转换为UTC格式
string dateUTC = paramDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
2.) Now I have created a method that will handle the convertion of UTC Date to PlainDate
2.)现在我已经创建了一个方法来处理UTC Date转换为PlainDate
public static string UTCtoPlainDate(string dateUTC)
{
if (string.IsNullOrEmpty(dateUTC)) return "";
DateTime dateTime;
// Assume date in UTC format, e.g. '2015-03-31T12:00:00.000Z'
DateTime.TryParseExact(dateUTC, "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.AssumeUniversal, out dateTime);
return dateTime.ToString("yyyy-MM-dd") ?? "";
}