* Re: time conversion
@ 2005-08-24 2:21 Suma Choudhary
0 siblings, 0 replies; 4+ messages in thread
From: Suma Choudhary @ 2005-08-24 2:21 UTC (permalink / raw)
To: lejanson, nanakos; +Cc: linux-c-programming
Hi
How about using time() and ctime() functions.
regards
suma
>>> "Nanakos Chrysostomos" <nanakos@wired-net.gr> 08/23/05 13:09 PM >>>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
void print_time ()
{
struct timeval tv;
struct tm* ptm;
char time_string[40];
long milliseconds;
gettimeofday (&tv, NULL);
ptm = localtime (&tv.tv_sec);
strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S",
ptm);
milliseconds = tv.tv_usec / 1000;
printf ("%s.%03ld\n", time_string, milliseconds);
}
main()
{
print_time();
}
I hope this helps.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread* time conversion
@ 2005-08-23 7:30 Lejanson C. Go
2005-08-23 7:42 ` Nanakos Chrysostomos
2005-08-23 14:07 ` kranthi
0 siblings, 2 replies; 4+ messages in thread
From: Lejanson C. Go @ 2005-08-23 7:30 UTC (permalink / raw)
To: linux-c-programming
Hi,
I had searched the net on how to convert unsigned long timestamp
to human readable format or maybe in struct timeval format. Any sample
code that you can share would be greatly appreciated.
Thanks.
Lejanson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: time conversion
2005-08-23 7:30 Lejanson C. Go
@ 2005-08-23 7:42 ` Nanakos Chrysostomos
2005-08-23 14:07 ` kranthi
1 sibling, 0 replies; 4+ messages in thread
From: Nanakos Chrysostomos @ 2005-08-23 7:42 UTC (permalink / raw)
To: Lejanson C. Go; +Cc: linux-c-programming
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
void print_time ()
{
struct timeval tv;
struct tm* ptm;
char time_string[40];
long milliseconds;
gettimeofday (&tv, NULL);
ptm = localtime (&tv.tv_sec);
strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S",
ptm);
milliseconds = tv.tv_usec / 1000;
printf ("%s.%03ld\n", time_string, milliseconds);
}
main()
{
print_time();
}
I hope this helps.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: time conversion
2005-08-23 7:30 Lejanson C. Go
2005-08-23 7:42 ` Nanakos Chrysostomos
@ 2005-08-23 14:07 ` kranthi
1 sibling, 0 replies; 4+ messages in thread
From: kranthi @ 2005-08-23 14:07 UTC (permalink / raw)
To: Lejanson C. Go; +Cc: linux-c-programming
I think this may serve u r purpose
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
int main()
{
time_t t; //Number in Unsigned format
printf("% u \n ",t);
time(&t);
printf("%s",ctime(&t)); // Time in Human readable format
return 0;
}
On Tue, 23 Aug 2005 15:30:13 +0800, Lejanson C. Go
<lejanson@ntsp.nec.co.jp> wrote:
> Hi,
>
> I had searched the net on how to convert unsigned long timestamp
> to human readable format or maybe in struct timeval format. Any sample
> code that you can share would be greatly appreciated.
> Thanks.
>
> Lejanson
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-08-24 2:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-24 2:21 time conversion Suma Choudhary
-- strict thread matches above, loose matches on Subject: below --
2005-08-23 7:30 Lejanson C. Go
2005-08-23 7:42 ` Nanakos Chrysostomos
2005-08-23 14:07 ` kranthi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).