1

我需要从微秒(保存在unsigned long long int变量中)传递到其表示为小时、分钟、秒、毫秒,即:

from 47072349659 to 13:04:32.350

从毫秒中找到了这种转换,但我似乎无法让它在我的情况下工作。也许问题是数字太长而无法存储在某些变量类型中?我正在使用unsigned long long int输入时间并尝试将 int、long、unsigned long long int 用于输出。

这是我的 C++ 代码:

unsigned long long int timestamp;

long milliseconds   = (long) (timestamp / 1000000) % 1000;
long seconds    = (long) ((timestamp / (1000)) % 60);
long minutes    = (long) ((timestamp / (60000)) % 60);
long hours      = (long) ((timestamp / (3600000)) % 24);
4

1 回答 1

3

我认为您的错误在于您的设备:

long milliseconds   = (long) (timestamp / 1000) % 1000;
long seconds    = (((long) (timestamp / 1000) - milliseconds)/1000)%60 ;
long minutes    = (((((long) (timestamp / 1000) - milliseconds)/1000) - seconds)/60) %60 
long hours      = ((((((long) (timestamp / 1000) - milliseconds)/1000) - seconds)/60) - minutes)/60
于 2013-01-29T10:31:04.577 回答