The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux Going Big Time and Prime Time Against Windows, UNIX (WSJ) (Addict 3D) iBot UNIX and Linux RSS News 0 06-21-2007 01:10 PM
Start time/end time and status of crontab job thambi Shell Programming and Scripting 3 05-16-2007 07:24 AM
How To Provide Time Sync Using Nts-150 Time Server On Unix Network? pesty UNIX for Advanced & Expert Users 2 03-21-2007 10:20 PM
Losing Time/Time cloclk azdauk UNIX for Dummies Questions & Answers 4 11-06-2003 05:33 AM
default time in Solaris 8 for time-wait eloquent99 UNIX for Dummies Questions & Answers 1 04-01-2003 06:45 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-02-2001
Registered User
 

Join Date: Sep 2001
Location: Israel
Posts: 8
Stumble this Post!
Question time in microseconds

Hi

I want to print the current local time in microseconds

How ?
__________________
Avner Hartuv
BMC Software
avner_hartuv@bmc.com
Work: 972-3-6451-729
Cell: 972-53-956273
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-04-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,449
Stumble this Post!
Code:
struct timeval tv;
struct timezone tz;
struct tm *tm;
gettimeofday(&tv, &tz);
tm=localtime(&tv.tv_sec);
printf(" %d:%02d:%02d %d \n", tm->tm_hour, tm->tm_min,
    tm->tm_sec, tv.tv_usec);
Reply With Quote
  #3 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Sep 2001
Location: Israel
Posts: 8
Stumble this Post!
Thank you

Thank you very much
__________________
Avner Hartuv
BMC Software
avner_hartuv@bmc.com
Work: 972-3-6451-729
Cell: 972-53-956273
Reply With Quote
  #4 (permalink)  
Old 07-29-2002
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Stumble this Post!
just a little more help for the C noob like myself.

i get these errors when i try to compile it. I must admit i do not know C.


OS=sol8
platform=E3500 (sparc)

Code:
$ cat milli.c

#include <stdlib.h>
#include <sys/time.h>

struct timeval tv;
struct timezone tz;
struct tm *tm;
gettimeofday(&tv, &tz);
tm=localtime(&tv.tv_sec);
printf(" %d:%02d:%02d %d \n", tm->tm_hour, tm->tm_min
,m->tm_sec, tv.tv_usec);


$ gcc milli.c
milli.c:7: parse error before '&' token
milli.c:7: warning: data definition has no type or storage class
milli.c:8: conflicting types for `tm'
milli.c:6: previous declaration of `tm'
milli.c:8: warning: initialization makes integer from pointer without a cast
milli.c:8: initializer element is not constant
milli.c:8: warning: data definition has no type or storage class
milli.c:9: parse error before string constant
milli.c:10: warning: conflicting types for built-in function `printf'
milli.c:10: warning: data definition has no type or storage class
Reply With Quote
  #5 (permalink)  
Old 07-29-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,449
Stumble this Post!
Try this...
Code:
#include <stdlib.h>
#include <sys/time.h>
main()
{
     struct timeval tv;
     struct timezone tz;
     struct tm *tm;
     gettimeofday(&tv, &tz);
     tm=localtime(&tv.tv_sec);
     printf(" %d:%02d:%02d %d \n", tm->tm_hour, tm->tm_min,
              m->tm_sec, tv.tv_usec);
     exit(0);
}
Reply With Quote
  #6 (permalink)  
Old 07-29-2002
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Stumble this Post!
and once again you prove im not worthy!!

now 1 last question.

$ ./a.out
17:30:40 806214

$ date
Mon Jul 29 17:30:43 GMT 2002

what is the 806214???


Reply With Quote
  #7 (permalink)  
Old 07-29-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,449
Stumble this Post!
That's the microseconds! In your example the gettimeofday system call occurred 806,214 microseconds after 17:30:40.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0