473,839 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting current time with milliseconds

19 New Member
hi all,

I want to take current time with milli seconds in C. Does it have any header file to include to produce time in milli seconds.

Please mail me if any of u know.

Thank you.
Oct 17 '06 #1
8 201685
tyreld
144 New Member
The "time" function in <time.h> will return the number of seconds since the epoch (ie. 00:00:00 on January 1, 1970, Coordinated Universal Time). The type of "time_t" is generally typedefed as "long int" on POSIX compliant systems. Finally, if we recall that a millisecond is 1/1000 of a second we can easily calculate the number of milliseconds since the epoch.

Expand|Select|Wrap|Line Numbers
  1. <time.h>
  2.  
  3. ...
  4.  
  5. time_t msec = time(NULL) * 1000;
  6.  
Oct 17 '06 #2
arne
315 Recognized Expert Contributor
hi all,

I want to take current time with milli seconds in C. Does it have any header file to include to produce time in milli seconds.

Please mail me if any of u know.

Thank you.
You may try the "gettimeofd ay" function. It reports the time down to microsecond level. The function is included via <sys/time.h>.
Oct 17 '06 #3
Banfa
9,065 Recognized Expert Moderator Expert
If you are using Windows rather than standard C you can call

GetSystemTimeAs FileTime(...)

with returns the current time as the number of 100-nanosecond intervals that have passed since January 1, 1601.
Oct 17 '06 #4
Harika
19 New Member
If you are using Windows rather than standard C you can call

GetSystemTimeAs FileTime(...)

with returns the current time as the number of 100-nanosecond intervals that have passed since January 1, 1601.
Hi Banfa,

Actually we want to count current time in milliseconds and then has to show such a way that hr/min/sec/msec.

Would u tell me the header files and functions in c required or else an example c program.

Thank you.
Oct 17 '06 #5
Banfa
9,065 Recognized Expert Moderator Expert
Would u tell me the header files and functions in c required or else an example c program.
Expand|Select|Wrap|Line Numbers
  1. #include "windows.h"
  2.  
  3. FILETIME now;
  4.  
  5. GetSystemTimeAsFileTime(&now);
  6.  
or if you want it split in to hours etc
Expand|Select|Wrap|Line Numbers
  1. #include "windows.h"
  2.  
  3. SYSTEMTIME now;
  4.  
  5. GetSystemTime(&now);
  6.  
Oct 17 '06 #6
Harika
19 New Member
Expand|Select|Wrap|Line Numbers
  1. #include "windows.h"
  2.  
  3. FILETIME now;
  4.  
  5. GetSystemTimeAsFileTime(&now);
  6.  
or if you want it split in to hours etc
Expand|Select|Wrap|Line Numbers
  1. #include "windows.h"
  2.  
  3. SYSTEMTIME now;
  4.  
  5. GetSystemTime(&now);
  6.  


hi Banfa,

Thanks for ur best reply. But it doesnot works in linux. I need header files which is included in linux. Would u help me pls....
Oct 24 '06 #7
arne
315 Recognized Expert Contributor
hi Banfa,

Thanks for ur best reply. But it doesnot works in linux. I need header files which is included in linux. Would u help me pls....
Please refer to my previous post mentioning the gettimeofday() function. It will provide what you need.
Oct 24 '06 #8
Incyc
1 New Member
This will give you the time in the format HH:MM:SS:mmm

Expand|Select|Wrap|Line Numbers
  1. timeval tp;
  2. gettimeofday(&tp, 0);
  3. time_t curtime = tp.tv_sec;
  4. tm *t = localtime(&curtime);
  5. printf("%02d:%02d:%02d:%03d\n", t->tm_hour, t->tm_min, t->tm_sec, tp.tv_usec/1000);
Apr 12 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
10733
by: MarthaR | last post by:
I am trying to add the current time to a field when the user clicks on the toggle button next to the field. I am getting a time of 12:00:00 AM each time I click the button. How do I get a return of the current time? MarthaR
18
36389
by: Tim Quon | last post by:
Hi I need to print the current time. I found an example where this is done as followed: long *mytime; time(mytime); printf("time: %s", ascitime(mytime); But this doesn't work and prints some ugly numbers.
4
9367
by: Gary Wessle | last post by:
Hi I am not getting current time with this program, what am I doing wrong? #include <ctime> #include <iostream> using namespace std; #define P(x) cout << #x " = " << (x) << "\n";
3
1838
by: Mark Ingram | last post by:
Hi, I'd like to know the best way of checking the current time during a demonstration product. At the minute i store the first run date, then compare that to the system time, but obviously a user can just change their clock back a month and continue using the product. I heard it is best to check the access time on a system dll? I had a quick look at the user32.dll file and realised the access time was the time my machine booted up, but...
2
2585
by: Mark Poppers | last post by:
I would like to get the current time(stamp) (including the milliseconds) and assign it into a string variable with a format like: xxxx mytime = getcurrentsystemtime(); string mytime = reformatto("yyy.mm.dd HH:MM:SS:MSMS", mytime); How do I do this ? The hours should be displayed in 24h mode Mark
1
1792
by: aramakri | last post by:
I just want to know when a particular function is called.Can anybody help me in getting this time in seconds.
4
15029
by: limnath | last post by:
Dear All, I am using Perl version v5.8.2 built for IBM AIX. I want to get the current time till the resolution of milliseconds. Now I am able to get till seconds using localtime function. Can anybody help me in getting the time till milliseconds? Many Many Thanks in advance.
30
521
by: Ashit Vora | last post by:
Hi, I want to find the current time stamp in micro sec precision. The requirement is, my function is executed in an infinite loop. I measure a value and check if the value computed is what i expected 9forget all this stuff). I want to print the time stamp every time that event occurs. So my requirement is printing the current timestamps.
1
2842
by: Neel | last post by:
Hi, I want to find the current time stamp in micro sec precision. The requirement is, my function is executed in an infinite loop. I measure a value and check if the value computed is what i expected 9forget all this stuff). I want to print the time stamp every time that event occurs. So my requirement is printing the current timestamps.
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10654
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10298
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7833
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7021
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5683
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4066
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.