473,663 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting time in milliseconds

Hi:
is there a way to get current system time in milliseconds...
which functions and headers??

thanks
pravesh
Nov 14 '05 #1
26 55710
"Pravesh" <pr************ ****@yahoo.com> wrote in message
news:e5******** *************** ***@posting.goo gle.com...
Hi:
is there a way to get current system time in milliseconds...
Not portably.
which functions and headers??


The standard functions for retrieving system time and
working with time are declared by the header <time.h>.
They including 'time()', 'localtime()', and 'gmtime()',
among others. However, the resolution of the time
is implementation-specific.

-Mike
Nov 14 '05 #2
> > Pravesh:
is there a way to get current system time in milliseconds...
"Mike Wahler" wrote:
Not portably. which functions and headers??

The standard functions for retrieving system time and
working with time are declared by the header <time.h>.
They including 'time()', 'localtime()', and 'gmtime()',
among others. However, the resolution of the time
is implementation-specific.


But if, conjecturally, some one put a gun to your head and said "I need
milliseconds from the arbitrary machine using C compiled on said machine,"
you wouldn't get your brains blown out, correct? In particular, is this not
true if you let a program "warm up" to an OS for, say, a minute? MPJ
Nov 14 '05 #3

"Merrill & Michele" <be********@com cast.net> wrote in message
news:er******** ************@co mcast.com...
Pravesh:
is there a way to get current system time in milliseconds...
"Mike Wahler" wrote:
Not portably. which functions and headers??

The standard functions for retrieving system time and
working with time are declared by the header <time.h>.
They including 'time()', 'localtime()', and 'gmtime()',
among others. However, the resolution of the time
is implementation-specific.


But if, conjecturally, some one put a gun to your head and said "I need
milliseconds from the arbitrary machine using C compiled on said machine,"
you wouldn't get your brains blown out, correct?


It's entirely possible that I would. "Arbitrary machine" might not
have the requested functionality. Or perhaps a C translator for it
does not exist.
In particular, is this not
true if you let a program "warm up" to an OS for, say, a minute? MPJ


Some platforms, operating systems, and C implementations do provide
the requested functionality, others do not. Also note that a C program
need not be hosted by an operating system at all.

-Mike
Nov 14 '05 #4
On Mon, 8 Nov 2004 19:34:34 -0600, "Merrill & Michele"
<be********@com cast.net> wrote in comp.lang.c:
Pravesh:
is there a way to get current system time in milliseconds...
"Mike Wahler" wrote:
Not portably.

which functions and headers??

The standard functions for retrieving system time and
working with time are declared by the header <time.h>.
They including 'time()', 'localtime()', and 'gmtime()',
among others. However, the resolution of the time
is implementation-specific.


But if, conjecturally, some one put a gun to your head and said "I need
milliseconds from the arbitrary machine using C compiled on said machine,"
you wouldn't get your brains blown out, correct? In particular, is this not
true if you let a program "warm up" to an OS for, say, a minute? MPJ


Sure, you can always multiply the return value of difftime() by 1000.

But there are a lot of systems out there that don't track time
accurately to the millisecond.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #5
> Pravesh:
> is there a way to get current system time in milliseconds...
"Mike Wahler" wrote:
Not portably.

> which functions and headers??

The standard functions for retrieving system time and
working with time are declared by the header <time.h>.
They including 'time()', 'localtime()', and 'gmtime()',
among others. However, the resolution of the time
is implementation-specific.


But if, conjecturally, some one put a gun to your head and said "I need
milliseconds from the arbitrary machine using C compiled on said machine," you wouldn't get your brains blown out, correct? In particular, is this not true if you let a program "warm up" to an OS for, say, a minute?

Jack Klein:
Sure, you can always multiply the return value of difftime() by 1000.

But there are a lot of systems out there that don't track time
accurately to the millisecond.


That systems don't track milliseconds doesn't mean that we can't track THEM
to the millisecond. That is, with a little elbow grease and the view that
the occurence of the next second can be seen as a Poisson process. The
following code is crude, but I think it illustrates that one isn't shackled
by notions smaller than a second. I think I recall that a "jiffy" is 10^-52
seconds. MPJ

#include <stdio.h>
#include <time.h>
int main (){
time_t timer;
long i, counter, aboutbillion, fiveseconds;
aboutbillion = 0;
counter = 0;
fiveseconds = (long)(time(&ti mer) + 5);
while (aboutbillion < fiveseconds){
aboutbillion = (long)time(&tim er);
++counter;
}
printf (" counter= %ld\n", counter);
printf (" timer= %ld\n", aboutbillion);
printf (" and five= %ld\n", fiveseconds);
return 0;
}
Nov 14 '05 #6
pr************* ***@yahoo.com (Pravesh) wrote in message news:<e5******* *************** ****@posting.go ogle.com>...
Hi:
is there a way to get current system time in milliseconds...
which functions and headers??

Short reply:in C, no.

Long reply:But there are libraries that define certain structures and functions
that let you manipulate time values.That is system/implementation dependant.Also
you will need to know why and where you are using it.And that's exactly OT here.
E.g:if you are on *nix systems you can probably find something like time.h,
look up on it.And Google for it!There are lots of resources available.

HTH
Suman.
Nov 14 '05 #7
Jack Klein wrote:
Sure, you can always multiply the return value of difftime() by 1000.


And then divide the result by 1000000.
Christian

Nov 14 '05 #8
pr************* ***@yahoo.com (Pravesh) wrote in message news:<e5******* *************** ****@posting.go ogle.com>...
Hi:
is there a way to get current system time in milliseconds...
which functions and headers??
Yes, there is Fucntion to compute/get time of the specified fuction.
(How much fucntion is taking time to execute),I think this is your Goal.

for linux --> #include <sys/time.h>
gettimeofday

for windows --> #include <time.h>
GetTickCount is the function
See the both the arguments in it
and You will be able to get the Time in milliseconds
Hope this will help you out.
If You have the problem then drop the mail.

Enjoy
Ranjeet
thanks
pravesh

Nov 14 '05 #9
Merrill & Michele <be********@com cast.net> wrote:
Jack Klein:
Sure, you can always multiply the return value of difftime() by 1000.

But there are a lot of systems out there that don't track time
accurately to the millisecond.
That systems don't track milliseconds doesn't mean that we can't track THEM
to the millisecond. That is, with a little elbow grease and the view that
the occurence of the next second can be seen as a Poisson process. The
following code is crude, but I think it illustrates that one isn't shackled
by notions smaller than a second. I think I recall that a "jiffy" is 10^-52
seconds. MPJ #include <stdio.h>
#include <time.h>
int main (){
time_t timer;
long i, counter, aboutbillion, fiveseconds;
aboutbillion = 0;
counter = 0;
fiveseconds = (long)(time(&ti mer) + 5);
There's nothing that guarantees that time_t is a time in seconds on
all systems, at least the C standard does only says that time_t is
a "arithmetic type capable of representing times".
while (aboutbillion < fiveseconds){
aboutbillion = (long)time(&tim er);
++counter;
}
printf (" counter= %ld\n", counter);
printf (" timer= %ld\n", aboutbillion);
printf (" and five= %ld\n", fiveseconds);
return 0;
}


Even if time_t does return times in seconds that won't do you any
good on a multi-tasking OS. What you try to do here is measure the
time a call of time() takes - but that will only give you a useful
result if the process gets all the CPU time during that 5 seconds.
But on most modern operating systems the CPU time gets distributed
between different processes, and the OS itself uses some time for
it's own purposes. So you don't have a chance to get a reproducible
value that way since you don't have any idea how much time the other
processes get (you don't even know how many there are) and how much
time the OS is going to need.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1788
by: Nicolas Verhaeghe | last post by:
I have designed an application which uses the Crystal Reports 8.5 ActiveX to show a report as a PDF. The report is compiled from a SQL database populated through web forms programmed in ASP. When the Active X is lauched, a PDF is pushed as a stream to Internet Explorer, which calls the Acrobat Reader plugin to view it. When some of my users click on the Back button to get out of the PDF report,
2
9076
by: Alejandro Javier Pomeraniec | last post by:
Hi ! Is there any way to get the time like the following example ? '2003-05-11 15:21:21' should return '15:21:21'
1
1756
by: Nuno Magalhaes | last post by:
This site: http://tycho.usno.navy.mil/cgi-bin/anim gives me the date at a specified moment but using HttpRequest and Response with this server is very bad. Does anyone knows how to get a high fidelity time in order to get my trial version software up and running? Give me some sites please so that I can retrieve an high fidelity time. With the site given above I only get two httpresponses and nothing more
2
6481
by: Sebastian Santacroce | last post by:
I'm trying to format datetime column in datagrid to a time format rather than date. I'm using code: Dim myGridTextBoxColumn As DataGridTextBoxColumn = New DataGridTextBoxColumn() myGridTextBoxColumn = CType(datagrid.TableStyles (0).GridColumnStyles("StartDate"), DataGridTextBoxColumn) myGridTextBoxColumn.Format="hh:mm:ss tt"
2
2790
by: beaker | last post by:
Hello, I'm writing a program (which will be running in the background 99% of the time) and I want to be able to work out how long it has been since the user last used the mouse and/or keyboard. I plan on using a Timer to do the checking periodically, but I'm not sure how to get the time of the last mouse click or keystroke. Any suggestions? I've seen examples on keyboard loggers but they seem to focus on capturing all keystrokes,...
3
6003
by: mangesh | last post by:
Hi , can anyone tell me how to find time in milliseconds on mac os . Is there any function in standard library for same . Regards Mangesh .
16
11112
by: psbasha | last post by:
Hi, Is there any functions available for finding the time from the system?.I would like to find the start time and end time of the processing of the application after execution. Thanks in advance PSB
3
1233
by: ren07 | last post by:
haii i need to get the time from the date time stamp which is stored in the database(SQL).............. i am getting the date time stamp like this..01-Jan-2000 08:00:00 i want it like..08:00:00.. can anyone help me please...
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
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
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
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...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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
5655
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
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.