如何将微秒转换为时间戳? [英] How do I convert microseconds into a timestamp?

查看:1356
本文介绍了如何将微秒转换为时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个未加密的.DAT文件中取出了这部分:

I took this piece from an unencrypted .DAT file:

代码:

00 e1 27 17 6f e6 69 c0

00 e1 27 17 6f e6 69 c0

这将转换为十进制的63,374,851,375,000,000。

Which translates to 63,374,851,375,000,000 in decimal. The units for the number are microseconds.

这个巨大的数字不能绕过1970年1月1日00:00:00格式;

And this huge number cannot bypass the 1st January 1970 00:00:00 format; such a format that most converters use today.

所以,是的。是否有使用1年1月1日格式的转换器?还是我该怎么做?

So, yes. Is there such a converter that uses the 1st January of the year 1 format? Or how shall I make one?

而且,时间戳记既是日期又是时间。

And by the way, a timestamp is both date and time.

推荐答案

您不会说自己使用的是哪种语言,如果它是.NET语言,则可以使用: http://msdn.microsoft.com/en-us/library/z2xf7zzk .aspx 对于该构造函数的输入以纳秒为单位(您确定您的数字以毫秒为单位,而不是以纳秒为单位吗?)。

You do not say what language are you using, if it is a .NET language, you can use: http://msdn.microsoft.com/en-us/library/z2xf7zzk.aspx for that constructor the input is in nanoseconds (are you sure that your number is in milliseconds and not in nanoseconds?).

以毫秒为单位,到纳秒的转换应该很容易:1毫秒= 1000000纳秒。

If you are sure it is in milliseconds, the conversion to nanoseconds should be easy: 1 millisecond = 1 000 000 nanoseconds.

但是我感觉那是十亿分之一秒,而不是毫秒...

But I have the feeling that those are nanoseconds and not milliseconds...

现在您已经告诉了我们以秒为单位 microseconds

Now that you have told us that it is in microseconds:

C#示例从十进制到yyyy dd MM hh:mm:ss

C# Example from decimal to yyyy dd MM hh:mm:ss



long microseconds = 63370738175000000;            
long ticks = microseconds * 10;
DateTime timestamp = new DateTime(ticks);
Console.WriteLine(timestamp.ToString("yyyy dd MM  hh:mm:ss"));

打印:

2009 20 02 02:49:35

2009 20 02 02:49:35

从yyyy dd MM hh:mm:ss到小数的另一种方式

The other way around from yyyy dd MM hh:mm:ss to decimal



String dateString = "2009 20 02  02:49:35";
DateTime timestamp = DateTime.ParseExact(dateString, "yyyy dd MM  hh:mm:ss",CultureInfo.CurrentCulture);
long ticks = timestamp.Ticks;
long microseconds = ticks / 10;
Console.WriteLine(microseconds);

打印:

63370694975000000

63370694975000000

如果要用十六进制表示,请输入:

And if you want it in hexadecimal just write:



Console.WriteLine(microseconds.ToString("X"));

然后它将打印:

E1234FB3278DC0

E1234FB3278DC0

如果您想用其他编程语言来回答,请在您的问题中添加。

If you want the answer in another programming language, please add that to you question.

这篇关于如何将微秒转换为时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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