6 posts / 0 new
Last post
Mohamad Azhar Ina...
aawara's picture
Offline
Mobile Conjurer
Joined: 9 Feb 2011
Posts:
Get System Time

Hi,
I was looking if there's a way to get the phone's current time and date, but could not find a way.

All i found was total no of seconds passed from 00:00:00 1st jan 1970 using maTime() from matime.h.

And second thing is maGetMilliSecondCount() which returns no. of seconds from unknown point of time(don't know what it returns exactly).

Also the Mosync API Reference http://www.mosync.com/files/imports/doxygen/latest/html/index.html specifies Time and date column but the methods given besides it are no where returning the date.

Can sum1 help?

Thanks & Regards.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi, you've got the time and date with maTime() and maLocalTime(), because it is a number you can easily tell if one datetime is before or after another. You can have dates before 1st Jan 1970 by having a negative number. This is how C and UNIX process times. This is called UNIX time.

You can convert the number into a string using sprint_time, or format it yourself by splitting it into a tm struct

MRae
MRae's picture
Offline
Joined: 28 Oct 2010
Posts:

Maybe you could use something like this for the time:

DateTime time;
DateTime timestamp;

timestamp = time.now();
int hour = timestamp.getHour();
int minute = timestamp.getMinute();
int second = timestamp.getSecond();
char timeNow[8];
sprintf(timeNow, "%i:%i:%i", hour, minute, second);

You have to include the library and add MAP.lib to your project.

Mohamad Azhar Ina...
aawara's picture
Offline
Mobile Conjurer
Joined: 9 Feb 2011
Posts:

Got it working. Thanks a lot Sam.

Posting the code for someone in need like me..............

                struct tm * tim_p = new tm;
		split_time(maTime(), tim_p);
		printf("system hour is %d ", tim_p->tm_hour);
		printf("system min is %d ", tim_p->tm_min);
		printf("system sec is %d ", tim_p->tm_sec);
		printf("Daylight Saving Time flag %d ", tim_p->tm_isdst);
		printf("Day of the month %d ", tim_p->tm_mday);
		printf("Months since January %d ", tim_p->tm_mon);
		printf("Days since Sunday %d ", tim_p->tm_wday);
		printf("Days since January 1 %d ", tim_p->tm_yday);
		printf("Years since 1900 %d ", tim_p->tm_year);

paulclinger
paulclinger's picture
Offline
Mobile Conjurer
Joined: 7 Aug 2011
Posts:

Is there a way to get more precision from maTime, for example, to milliseconds, or better to microsecond? Or an alternative? Thanks.

Paul.

paulclinger
paulclinger's picture
Offline
Mobile Conjurer
Joined: 7 Aug 2011
Posts:

I found maGetMilliSecondCount that may do what I need (haven't tested it yet). Paul.