返回自1970/01/01以来的毫秒数 [英] Return the number of milliseconds since 1970/01/01

查看:109
本文介绍了返回自1970/01/01以来的毫秒数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascrip中

in javascrip

var d = new Date();
var n = d.getTime();





how in c#?

推荐答案

OriginalGriff发布的解决方案很好,除了最后一行应使用TotalMilliseconds属性而不是Millsseconds:
The solution posted by OriginalGriff is good, except that the last line should use the TotalMilliseconds property, instead of Milliseconds:
DateTime baseDate = new DateTime(1970, 1, 1);
TimeSpan diff = DateTime.Now - baseDate;
Console.WriteLine(diff.TotalMilliseconds);


Milliseconds属性仅给出TimeSpan的毫秒分量(总计年,天,小时,分钟和秒的数量后剩余的数量),而TotalMilliseconds给出的总毫秒数由值.


The Milliseconds property just gives the milliseconds component of the TimeSpan (the amount left-over after totaling the number of years, days, hours, minutes and seconds), while TotalMilliseconds gives the total number of milliseconds represented by the value.


尝试:
DateTime baseDate = new DateTime(1970, 1, 1);
TimeSpan diff = DateTime.Now - baseDate;
Console.WriteLine(diff.Milliseconds);


您好,您可以这样做....

var d = new Date("1970年1月1日");
var n = d.getMilliseconds();


C#

DateTime dt = Convert.ToDateTime("1970/01/01");

long k = dt.Ticks;
Hi, You can do like this....

var d = new Date("January 01, 1970");
var n = d.getMilliseconds();


C#

DateTime dt=Convert.ToDateTime("1970/01/01");

long k= dt.Ticks;


这篇关于返回自1970/01/01以来的毫秒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆