0

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):

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:

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

It's getting late. Thanks in advance!.

Community
  • 1
  • 1
dr.Crow
  • 1,493
  • 14
  • 17

1 Answers1

0

I somehow achieve what I want to by the following approach

1.) At backend Convert the DateTime to UTC Format

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

        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") ?? "";
    }
dr.Crow
  • 1,493
  • 14
  • 17