blob: 93f8e5db6e73b7dbc71d1711239ce8add50ad55f [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/ports/SkTime_Unix.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "SkTime.h"
19
reed@android.com8a1c16f2008-12-17 15:59:43 +000020#include <sys/time.h>
21#include <time.h>
22
23void SkTime::GetDateTime(DateTime* dt)
24{
25 if (dt)
26 {
27 time_t m_time;
28 time(&m_time);
29 struct tm* tstruct;
30 tstruct = localtime(&m_time);
31
32 dt->fYear = tstruct->tm_year;
33 dt->fMonth = SkToU8(tstruct->tm_mon + 1);
34 dt->fDayOfWeek = SkToU8(tstruct->tm_wday);
35 dt->fDay = SkToU8(tstruct->tm_mday);
36 dt->fHour = SkToU8(tstruct->tm_hour);
37 dt->fMinute = SkToU8(tstruct->tm_min);
38 dt->fSecond = SkToU8(tstruct->tm_sec);
39 }
40}
41
42SkMSec SkTime::GetMSecs()
43{
44 struct timeval tv;
45 gettimeofday(&tv, NULL);
46 return (SkMSec) (tv.tv_sec * 1000 + tv.tv_usec / 1000 ); // microseconds to milliseconds
yangsu@google.com3c1b28d2011-07-07 19:34:18 +000047}