locked
is there any funtion exists in javascript like c# function datatime.specifykind RRS feed

  • Question

  • User2102072086 posted

    DateTime.SpecifyKind(Convert.ToDateTime(filterParam.dtFrom).Date, DateTimeKind.Utc);

    well the question is.

    i get datetime in json string "2019-01-01T00:00:000Z"

    i do not want to remove Z out of it and i want to show it on page with ddMMyyyy formate, when i use moment(day).format(timeFormat);.

    this reduces my date by one as my local is America. so please suggest how should I format.

    Thursday, April 9, 2020 6:28 AM

Answers

  • User-1330468790 posted

    Hi rajemessage,

      

    I think what you need might be below function.

    moment(time).tz(timezone).format(format);  //moment-timezone-with-data.min.js contains this function
    
    OR
    
    moment(time).utc().format(format); // moment.min.js contains this function

    Let's take "2019-01-01T00:00:00Z" as an example. The result will be different with different timezones.

    JS Code:

    var time = moment("2019-01-01T00:00:00Z");
    var format = 'MMMM Do YYYY hh:mm:ss';
    
    var newYork = time.tz('America/New_York').format(format);
    
    var losAngeles = time.tz('America/Los_Angeles').format(format);
    
    var tokyo = time.tz('Asia/Tokyo').format(format);
                
    var utc = time.utc().format(format);

    Result:

    New York: December 31st 2018 07:00:00
    Los Angeles: December 31st 2018 04:00:00
    Tokyo: January 1st 2019 09:00:00
    UTC: January 1st 2019 12:00:00

      

    Hope this can help you.

    Best regards,

    Sean

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 9, 2020 9:15 AM