JS implements the method of converting DateTime Json type of Asp. Net to standard time

  • 2021-07-07 06:16:57
  • OfStack

This article illustrates the method of JS implementation converting DateTime Json type of Asp. Net to standard time. Share it for your reference, as follows:

Go straight to the example as follows:


onload = function () {
  var thisDateText = '/Date(1401076829)/';
  document.write(getLocalTime(thisDateText));
};
function getLocalTime(dateText) {
  dateText = dateText.replace("/Date(", "").replace(")/", "");
  /*
     It should be noted that: 
       Do not put the Date( Such characters are also passed in and must be processed first 1 Next, it's very convenient to handle it 
     You can use the replace Method 
     Such as: replace("/Date(","").replace(")/","");
  */
  // Return  2014 Year 5 Month 26 Day   Afternoon 12:00
  //return new Date(parseInt(dateText) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
  // Return  2014 Year 5 Month 26 Day   Afternoon 12:0
  //return new Date(parseInt(dateText) * 1000).toLocaleString().substr(0, 17);
  // Return  2014-5-26 12:00:29
  return new Date(parseInt(dateText) * 1000).toLocaleString().replace(/ Year | Month /g, "-").replace(/ Day /g, " ").replace(/ Morning /g, " ").replace(/ Afternoon /g, " ");
}

PS: Friends who are interested in JavaScript time and date display can also refer to this online tool:

Unix timestamp (timestamp) conversion tool:
http://tools.ofstack.com/code/unixtime

Online time query around the world:
http://tools.ofstack.com/zhuanhuanqi/worldtime

Online perpetual calendar:
http://tools.ofstack.com/bianmin/wannianli

Page perpetual calendar calendar:
http://tools.ofstack.com/bianmin/webwannianli

For more information about JavaScript, please see the topics of this site: "Summary of JavaScript Time and Date Operation Skills", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Error and Debugging Skills", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript Traversal Algorithm and Skills" and "Summary of JavaScript Mathematical Operation Usage"

I hope this article is helpful to everyone's JavaScript programming.


Related articles: