1 2/* 3 * Copyright 2009 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10#include "SkTime.h" 11 12void SkTime::GetDateTime(DateTime* dt) 13{ 14 if (dt) 15 { 16 SYSTEMTIME st; 17 TIME_ZONE_INFORMATION timeZoneInfo; 18 int tz_bias; 19 GetLocalTime(&st); 20 // https://gist.github.com/wrl/8924636 21 switch (GetTimeZoneInformation(&timeZoneInfo)) { 22 case TIME_ZONE_ID_STANDARD: 23 tz_bias = -timeZoneInfo.Bias - timeZoneInfo.StandardBias; 24 break; 25 case TIME_ZONE_ID_DAYLIGHT: 26 tz_bias = -timeZoneInfo.Bias - timeZoneInfo.DaylightBias; 27 break; 28 default: 29 tz_bias = -timeZoneInfo.Bias; 30 break; 31 } 32 dt->fTimeZoneMinutes = SkToS16(tz_bias); 33 dt->fYear = st.wYear; 34 dt->fMonth = SkToU8(st.wMonth); 35 dt->fDayOfWeek = SkToU8(st.wDayOfWeek); 36 dt->fDay = SkToU8(st.wDay); 37 dt->fHour = SkToU8(st.wHour); 38 dt->fMinute = SkToU8(st.wMinute); 39 dt->fSecond = SkToU8(st.wSecond); 40 } 41} 42 43SkMSec SkTime::GetMSecs() 44{ 45 FILETIME ft; 46 LARGE_INTEGER li; 47 GetSystemTimeAsFileTime(&ft); 48 li.LowPart = ft.dwLowDateTime; 49 li.HighPart = ft.dwHighDateTime; 50 __int64 t = li.QuadPart; /* In 100-nanosecond intervals */ 51 return (SkMSec)(t / 10000); /* In milliseconds */ 52} 53