From: Yoder, J. <Joh...@am...> - 2006-09-19 16:08:21
|
I think you're reinventing the wheel here. All that is needed to get the date in that format is `/bin/date +%Y%m%d%H%M%S` which works on most *nix systems. All you are doing the "+%Y"... is just reformatting the output of the date command. =20 Regards, =20 John Yoder =20 ________________________________ From: lin...@li... [mailto:lin...@li...] On Behalf Of Bui Sy Phong Sent: Tuesday, September 19, 2006 8:49 AM To: lin...@li... Subject: [Linux-fbdev-users] Question on time system =20 Hi everybody, I know that i post this question in a wrong place, but if someone can help me to resolve it, it will be wonderful for me. In fact, i must write a little program wich diplay the local time of system on this format (a string) : Year/Mount/Day/Hour/Minute/Second , like : 20060919164421=20 So, i can get the number of second since : 01/01/1970 at 00:00:00 but i dont know how to convert this to a string like above. Here's my little code to get the number of second since 01/01/1970 : #include < stdio.h> #include <time.h> #include <stdint.h> int main(void) { system("date"); printf("\n"); time_t result; result =3D time(NULL); printf("%s%ju secs since January 1, 1970 0:00 UTC\n",=20 asctime(localtime(&result)), (uintmax_t)result); unsigned int seconds =3D (uintmax_t)result; printf("%u\n", seconds); return(0); =20 } I know that i must use strftime() to convert but i dont know how.=20 So, i post this question here. And waiting for your helpful. Thanks very much. P/S : I dont care about Timezone (it's always in UTC - GMT) |
From: Bui Sy P. <bui...@gm...> - 2006-09-20 07:53:22
|
It's works perfectly for me. Thanks so much ... I'm newbie on system programation so i dont know that i'm reinventing the wheel :) Thanks so much for your helpful. Sy Phong, 2006/9/19, Yoder, John <Joh...@am...>: > > I think you're reinventing the wheel here. All that is needed to get the > date in that format is `/bin/date +%Y%m%d%H%M%S` which works on most *nix > systems. All you are doing the "+%Y"=85 is just reformatting the output o= f the > date command. > > > > Regards, > > > > John Yoder > > > ------------------------------ > > *From:* lin...@li... [mailto: > lin...@li...] *On Behalf Of *Bui Sy > Phong > *Sent:* Tuesday, September 19, 2006 8:49 AM > *To:* lin...@li... > *Subject:* [Linux-fbdev-users] Question on time system > > > > Hi everybody, > > I know that i post this question in a wrong place, but if someone can hel= p > me to resolve it, it will be wonderful for me. > > In fact, i must write a little program wich diplay the local time of > system on this format (a string) : Year/Mount/Day/Hour/Minute/Second , li= ke > : 20060919164421 > > So, i can get the number of second since : 01/01/1970 at 00:00:00 but i > dont know how to convert this to a string like above. > > Here's my little code to get the number of second since 01/01/1970 : > > #include < stdio.h> > #include <time.h> > #include <stdint.h> > > > int main(void) > { > system("date"); > printf("\n"); > time_t result; > result =3D time(NULL); > printf("%s%ju secs since January 1, 1970 0:00 UTC\n", > asctime(localtime(&result)), > (uintmax_t)result); > unsigned int seconds =3D (uintmax_t)result; > printf("%u\n", seconds); > return(0); > > > } > > I know that i must use strftime() to convert but i dont know how. > > So, i post this question here. And waiting for your helpful. > > Thanks very much. > > P/S : I dont care about Timezone (it's always in UTC - GMT) > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > > _______________________________________________ > Linux-fbdev-users mailing list > Lin...@li... > https://lists.sourceforge.net/lists/listinfo/linux-fbdev-users > > > |