Contrastive analysis of conversion between Net and JS time and date formats

  • 2021-08-05 09:40:04
  • OfStack

In this paper, an example is given to analyze the conversion of time and date formats between. Net and JS. Share it for your reference, as follows:

The integer 1415349957524 in Js actually represents the number of milliseconds between 00:00 on 1.1, 1970 and some time point today. In. Net, we can use the Ticks attribute to get the number of milliseconds between 0001.1. 1 00: 00:00 and some point in time today.

The specific code implementation is as follows:

JS:


// Get 1970.1.1 00:00:00 Milliseconds up to now 
var milDate = +(new Date);

. Net:


// Get 1970.1.1 00:00:00 Milliseconds up to now 
var dateStage = new DateTime(1970, 1, 1);
var dateNow = DateTime.Now.ToUniversalTime();
var dateNowTs = new TimeSpan(dateNow.Ticks - dateStage.Ticks);
var dateMil = (long)dateNowTs.TotalMilliseconds;

PS: Friends who are interested in displaying time and date can also refer to the online tools of this site:

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 readers interested in asp. net related contents, please check the topics of this site: "asp. net Operation json Skills Summary", "asp. net String Operation Skills Summary", "asp. net Operation XML Skills Summary", "asp. net File Operation Skills Summary", "asp.net ajax Skills Summary" and "asp. net Cache Operation Skills Summary".

I hope this paper is helpful to everyone's asp. net programming.


Related articles: