blob: f58342b5f27c31566c43a7fd9e31f60388d0e5ac [file] [log] [blame]
yangsu@google.com2eff7e22011-06-24 15:57:30 +00001//#if defined(SK_BUILD_FOR_IOS)
2#include "SkTime.h"
3#include <sys/time.h>
4#include <Foundation/Foundation.h>
5void SkTime::GetDateTime(DateTime* dt)
6{
7 if (dt)
8 {
9 NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
10 NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |
11 NSWeekCalendarUnit | NSDayCalendarUnit |
12 NSHourCalendarUnit | NSMinuteCalendarUnit |
13 NSSecondCalendarUnit;
14
15 NSDate *date = [NSDate date];
16 NSDateComponents *dateComponents = [calendar components:unitFlags
17 fromDate:date];
18 dt->fYear = SkToU16([dateComponents year]);
19 dt->fMonth = SkToU8([dateComponents month]);
20 dt->fDayOfWeek = SkToU8([dateComponents weekday]);
21 dt->fDay = SkToU8([dateComponents day]);
22 dt->fHour = SkToU8([dateComponents hour]);
23 dt->fMinute = SkToU8([dateComponents minute]);
24 dt->fSecond = SkToU8([dateComponents second]);
25 }
26}
27
28SkMSec SkTime::GetMSecs()
29{
30 struct timeval tv;
31 gettimeofday(&tv, NULL);
32 return (SkMSec) (tv.tv_sec * 1000 + tv.tv_usec / 1000 ); // microseconds to milliseconds
33}
34//#endif