UnixTime到可读日期 [英] UnixTime to readable date
本文介绍了UnixTime到可读日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
C ++:获取当前时间和日期
是将UnixTime转换为日期的最佳方法?
What is the best way to convert UnixTime to a date?
是否有函数或算法?
推荐答案
Unix时间是自纪元以来的秒数(1970-01-01)。根据您的意思,您可以使用将它转换为 struct tm
localtime 或将其转换为包含 strftime 的字符串。
Unix time is seconds since epoch (1970-01-01). Depending on what you mean, you can convert it to a struct tm
with localtime or convert it to a string with strftime.
time_t t = time(NULL);
struct tm *tm = localtime(&t);
char date[20];
strftime(date, sizeof(date), "%Y-%m-%d", tm);
这篇关于UnixTime到可读日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文