有人能解释如何将十六进制TimeDateStamp DWORD值转换为人类可读的格式吗?
我只是好奇如何将0x62444DB4这样的值转换为“2022年3月30日星期三10:31:48下午”
当然,我试着在谷歌上搜索,却找不到任何解释。但也有在线转换器可用。
但我只想为自己转换这些价值。
发布于 2022-04-04 14:41:05
您的值是32位时间戳。
日期时间值是32位Unix时间戳:自1/1/1970以来的秒数。
在大多数编程语言中,您可以直接使用十六进制符号。
实现不应仅由一个人来完成,因为许多工程都在其中进行。闰年,甚至闰秒,时区,夏令时,UTC.在使用时间戳时,需要解决所有这些问题。
我在下面添加了我的粗略计算,作为一个示范。一定要使用现有的包或库来处理时间戳。
有关演示,请参阅下面的JavaScript代码。
在这里,我将您的值乘以1000,因为JavaScript以毫秒为单位工作。但否则,这同样适用于其他系统。
let timestamp = 0x62444DB4;
let dateTime = new Date(timestamp * 1000);
console.log('Timestamp in seconds:', timestamp);
console.log('Human-Readable:', dateTime.toDateString() + ' ' + dateTime.toTimeString());
// Rough output, just for the time.
// Year month and day get really messy with timezones, leap years, etc.
let hours = Math.floor(timestamp/3600) % 24;
let minutes = Math.floor(timestamp/60) % 60;
let seconds = Math.floor(timestamp) % 60;
console.log('Using our own time calculation:', hours + ':' + minutes + ':' + seconds);
https://stackoverflow.com/questions/71738565
复制相似问题