Converting time_t to int

前端 未结 3 1796
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 03:05

I want to convert a given time into epoch(time_t) and vice versa. can anyone tell what is the routine or algorithm for this?

Thanks

Update

3条回答
  •  天命终不由人
    2020-12-06 03:46

    You should cast it to a long int instead of int.

    long int t = static_cast time(NULL);
    

    An int might not be enough to hold the time, for example, on my platform, time_t is a typedef of __int64.

提交回复
热议问题