本文介绍了UINT64 UTC时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个UTC日期时间而不存储在UINT64的格式,例如: 20090520145024798
我需要得到的小时,分​​钟,秒和毫秒出这段时间。我可以通过将其转换为字符串,并使用子做到这一点很容易。然而,这code需要非常快,所以我想避免字符串操作。有没有更快的方法,可能使用位操作做到这一点?哦,这个需要用C做++在Linux上的方式。


解决方案

  UINT64 U = 20090520145024798;
无符号长W = U%10亿;
无符号毫秒= W%1000;
W / = 1000;
无符号秒= W%100;
W / = 100;
无符号分钟= W%100;
无符号小时= W / 100;
无符号长V = W / 10亿;
签名天= V%100;
体积/ = 100;
无符号月= v%的100;
无符号年= V / 100;

为什么这个解决方案从 UINT64 U 切换到 unsigned long类型是W (原因和 v ),在中间的是,YYYYMMDD和HHMMSSIII适合32位和32位除法比在一些系统上的64位除法快。

I have a UTC date time without the formatting stored in a uint64, ie: 20090520145024798I need to get the hours, minutes, seconds and milliseconds out of this time. I can do this very easily by converting it to a string and using substring. However, this code needs to be very fast so I would like to avoid string manipulations. Is there faster way, perhaps using bit manipulation to do this? Oh by the way this needs to be done in C++ on Linux.

解决方案
uint64 u = 20090520145024798;
unsigned long w = u % 1000000000;
unsigned millisec = w % 1000;
w /= 1000;
unsigned sec = w % 100;
w /= 100;
unsigned min = w % 100;
unsigned hour = w / 100;
unsigned long v = w / 1000000000;
unsigned day = v % 100;
v /= 100;
unsigned month = v % 100;
unsigned year = v / 100;

The reason why this solution switches from uint64 u to unsigned long w (and v) in the middle is that the YYYYMMDD and HHMMSSIII fit to 32 bits, and 32-bit division is faster than 64-bit division on some systems.

这篇关于UINT64 UTC时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:33