转换日期为毫秒 [英] Convert Date to Milliseconds

查看:249
本文介绍了转换日期为毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Visual Studio 2010中,MVC 3和C#的工作。我创造一些highcharts并需要有x轴是日期。我从数据库中提取的日期,并把它们添加到,然后将传递到highcharts阵列。我认为highcharts要求的日期是在毫秒格式。何去有关转换的'12 /二千零十一分之二十零下午5时10分13秒日期时间为例,以毫秒为单位?

I am working with Visual Studio 2010, MVC 3 and C#. I am creating some highcharts and need to have the x-axis be a date. I am pulling the dates from a database and adding them to and array that will then be passed to highcharts. I think highcharts requires the dates to be in millisecond format. Ho do I go about converting a DateTime of '12/20/2011 5:10:13 PM" for example to milliseconds?

推荐答案

一旦你弄清楚你要计算从毫秒什么,你正好可以从另外一个DateTime对象得到一个时间跨度对象。从时间跨度,你可以得到TotalMilliseconds。

Once you figure out what you want to calculate milliseconds from, you can just take one DateTime object from another to get a TimeSpan object. From TimeSpan you can get TotalMilliseconds.

换句话说,如果起点和终点是datetime对象,你可以这样做:

In other words, if start and end are DateTime objects, you can do this:

double milliseconds = (end - start).TotalMilliseconds;

这篇关于转换日期为毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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