I need to get pure UTC time in application level.
It should not be changed by user or location or anything else.
When I try with System.currentTimeMillis() or getTime() of Date class,
they always return value of local time. If user change date or time,
the return value is also changed.
I found handleEndOfInit method in android_modem.c (external\qemu
\telephony)
and the method is like below.
Probably, the variable "utc" is what I want.
1. Is the android_modem.c for emulator??
2. If it is, I think there must be similar file for target. Where is
it?
3. How can I get the "utc" value in my application?
static const char*
handleEndOfInit( const char* cmd, AModem modem )
{
time_t now = time(NULL);
struct tm utc, local;
long e_local, e_utc;
long tzdiff;
char tzname[64];
tzset();
utc = *gmtime( &now );
local = *localtime( &now );
e_local = local.tm_min + 60*(local.tm_hour + 24*local.tm_yday);
e_utc = utc.tm_min + 60*(utc.tm_hour + 24*utc.tm_yday);
if ( utc.tm_year < local.tm_year )
e_local += 24*60;
else if ( utc.tm_year > local.tm_year )
e_utc += 24*60;
tzdiff = e_local - e_utc; /* timezone offset in minutes */
/* retrieve a zoneinfo-compatible name for the host timezone
*/
{
char* end = tzname + sizeof(tzname);
char* p = bufprint_zoneinfo_timezone( tzname, end );
if (p >= end)
strcpy(tzname, "Unknown/Unknown");
/* now replace every / in the timezone name by a "!"
* that's because the code that reads the CTZV line is
* dumb and treats a / as a field separator...
*/
p = tzname;
while (1) {
p = strchr(p, '/');
if (p == NULL)
break;
*p = '!';
p += 1;
}
}
/* as a special extension, we append the name of the host's time
zone to the
* string returned with %CTZ. the system should contain special
code to detect
* and deal with this case (since it normally relied on the
operator's country code
* which is hard to simulate on a general-purpose computer
*/
return amodem_printf( modem, "%%CTZV: %02d/%02d/%02d:%02d:%02d:%02d
%c%d:%d:%s",
(utc.tm_year + 1900) % 100, utc.tm_mon + 1, utc.tm_mday,
utc.tm_hour, utc.tm_min, utc.tm_sec,
(tzdiff >= 0) ? '+' : '-', (tzdiff >= 0 ? tzdiff : -
tzdiff) / 15,
(local.tm_isdst > 0),
tzname );
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en