You must Sign In to post a response.
  • Category: General

    Convert date time to JSON date format

    Hi Team,

    How can we get JSON data from datetime. For example:
    Datetime = "12/11/2015";
    JSON date should result as :
  • #761687
    Hi Arun.

    Try the following javascript function to convert normal date to json format.

    function JSONDate (strDate)
    var dt = new Date (strDate);
    var newDate = new Date( Date .UTC
    (dt.getFullYear(), dt.getMonth(), dt.getDate(),
    dt.getHours(), dt.getMinutes(), dt.getSeconds(),
    return '/Date(' + newDate.getTime() + ')/' ;

    call the function with in the script.

    Sridhar Thota.
    Editor: DNS Forum.

  • #761709
    you can try Serialize and Deserialize. That will handle all those issue.
    By Nathan
    Direction is important than speed

  • #761714
    Hai Arun,
    I think you can use the Parse method for the JSON class object as below:

    DateTime dt= DateTime.Parse("12/11/2015");
    var obj = JSON.parse(dt);

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #761743
    Use this:

    var n = new Date('12/11/2015').getTime();
    alert(n); // n = 1449766800000

Sign In to post your comments