如何将微秒转换为时间戳?

发布于 2024-09-19 15:45:29 字数 287 浏览 9 评论 0原文

我从未加密的 .DAT 文件中获取了这段代码:

Code:

00 e1 27 17 6f e6 69 c0

十进制转换为 63,374,851,375,000,000。该数字的单位是微秒。

而这个巨大的数字无法绕过 1st January 1970 00:00:00 格式;目前大多数转换器都使用这种格式。

所以,是的。是否有这样一个使用当年 1 月 1 日格式的转换器?或者我该如何制作一个?

顺便说一句,时间戳既是日期又是时间。

提前致谢!

I took this piece from an unencrypted .DAT file:

Code:

00 e1 27 17 6f e6 69 c0

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

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

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.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

栩栩如生 2024-09-26 15:45:29

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

如果您确定它以毫秒为单位,则转换为纳秒应该很容易:1 毫秒 = 1 000 000 纳秒。

但我感觉这些是纳秒而不是毫秒...

现在您已经告诉我们它的单位是微秒:

C# 从十进制到 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

相反,从 yyyy dd MM hh:mm:ss 到十进制


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

如果你想要十六进制,只需写:


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

那么它将打印:

E1234FB3278DC0

如果你想要另一个答案编程语言,请将其添加到您的问题中。

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?).

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...

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

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"));

It prints:

2009 20 02 02:49:35

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);

It prints:

63370694975000000

And if you want it in hexadecimal just write:


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

Then it will print:

E1234FB3278DC0

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

女皇必胜 2024-09-26 15:45:29

在 JAVA 中要将微秒转换为 java.sql.Timestamp

public static Timestamp getTimestampFromMicros(long pMicros) {
  long millis = TimeUnit.MICROSECONDS.toMillis(pMicros);
  long shaaritInMicros = pMicros - TimeUnit.MILLISECONDS.toMicros(millis);
  Timestamp ts = new Timestamp(millis);
  long nanos = ts.getNanos() + TimeUnit.MICROSECONDS.toNanos(shaaritInMicros);
  ts.setNanos((int)nanos);
  return ts;
}

In JAVA in order to convert microseconds into java.sql.Timestamp:

public static Timestamp getTimestampFromMicros(long pMicros) {
  long millis = TimeUnit.MICROSECONDS.toMillis(pMicros);
  long shaaritInMicros = pMicros - TimeUnit.MILLISECONDS.toMicros(millis);
  Timestamp ts = new Timestamp(millis);
  long nanos = ts.getNanos() + TimeUnit.MICROSECONDS.toNanos(shaaritInMicros);
  ts.setNanos((int)nanos);
  return ts;
}
同展鸳鸯锦 2024-09-26 15:45:29

使用下面的 Java 代码将微秒转换为日期和时间,

   long msec = microseconds * 1/1000;
   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
   dateFormat.format(msec);

这将返回,
2016-01-27 03:41:12

Use below Java code to covert microseconds to date and time,

   long msec = microseconds * 1/1000;
   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
   dateFormat.format(msec);

Which will returns,
2016-01-27 03:41:12

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文