yangsu@google.com | 2eff7e2 | 2011-06-24 15:57:30 +0000 | [diff] [blame] | 1 | //#if defined(SK_BUILD_FOR_IOS) |
| 2 | #include "SkTime.h" |
| 3 | #include <sys/time.h> |
| 4 | #include <Foundation/Foundation.h> |
| 5 | void 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 | |
| 28 | SkMSec 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 |