blob: 84f1a4e374bbcd58bf56658cff665b842eb12c48 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTime.h"
#include "SkTypes.h"
#include <sys/time.h>
#include <time.h>
void SkTime::GetDateTime(DateTime* dt)
{
if (dt)
{
tzset(); // initialize timezone variable;
time_t m_time;
time(&m_time);
struct tm* tstruct;
tstruct = localtime(&m_time);
int offset = tstruct->tm_isdst == 1 ? 60 : 0;
// http://pubs.opengroup.org/onlinepubs/009695399/basedefs/time.h.html
dt->fTimeZoneMinutes = SkToS16(offset - timezone / 60);
dt->fYear = tstruct->tm_year + 1900;
dt->fMonth = SkToU8(tstruct->tm_mon + 1);
dt->fDayOfWeek = SkToU8(tstruct->tm_wday);
dt->fDay = SkToU8(tstruct->tm_mday);
dt->fHour = SkToU8(tstruct->tm_hour);
dt->fMinute = SkToU8(tstruct->tm_min);
dt->fSecond = SkToU8(tstruct->tm_sec);
}
}
SkMSec SkTime::GetMSecs()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (SkMSec) (tv.tv_sec * 1000 + tv.tv_usec / 1000 ); // microseconds to milliseconds
}
|