Mac/IOS/linux获取当前时间包含微秒毫秒的代码


#include <sys/time.h>

1
struct UnityLocalTimeStat 2 { 3 int Year; 4 int Month; 5 int DayOfWeek; 6 int Day; 7 int Hour; 8 int Min; 9 int Sec; 10 int USec; 11 12 UnityLocalTimeStat() 13 { 14 memset(this, 0, sizeof(*this)); 15 } 16 };
 1 void UnityGetLocalSystemTime(UnityLocalTimeStat& OutTimeStat)
 2 {
 3     struct timeval Time;
 4     gettimeofday(&Time, NULL);
 5     
 6     struct tm LocalTime;
 7     localtime_r(&Time.tv_sec, &LocalTime);
 8     
 9     OutTimeStat.Year = LocalTime.tm_year + 1900;
10     OutTimeStat.Month = LocalTime.tm_mon + 1;
11     OutTimeStat.DayOfWeek = LocalTime.tm_wday;
12     OutTimeStat.Day = LocalTime.tm_mday;
13     OutTimeStat.Hour = LocalTime.tm_hour;
14     OutTimeStat.Min = LocalTime.tm_min;
15     OutTimeStat.Sec = LocalTime.tm_sec;
16     OutTimeStat.USec = Time.tv_usec;
17 }

 

posted @ 2016-11-03 09:51  bodong  阅读(965)  评论(0编辑  收藏