Operating System - HP-UX
1832541 Members
4640 Online
110043 Solutions
New Discussion

Re: how to get milli-second

 
SOLVED
Go to solution
Gary Yu
Super Advisor

how to get milli-second

Hi all,

Could anybody point to me what is the command to get system time upto milli-second, "date" can only go as deep as second, I need to do some more precise calculation based on time stamp I can get.

thanks,
Gary
7 REPLIES 7
Todd McDaniel_1
Honored Contributor

Re: how to get milli-second

I am pretty sure there is no MS parm for the DATE command...

There may well be a script that can calculate it based on the system time.

Of course, I reserve the right to be totally misinformed.
Unix, the other white meat.
Vijaya Kumar_3
Respected Contributor

Re: how to get milli-second

I really dont know to find the date in ms.

here is a thread that does with oracle: check it out:
http://forums1.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F1%2C%2C0x464e7b8d1de3d5118ff40090279cd0f9%2C00.html&admit=716493758+1067274938940+28353475

Thanks
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: how to get milli-second

If you want to do this, you are going to have to write a bit of C using the gettimeofday() function. Man gettimeofday for details. Now for the bad news, it is pretty much looney tunes to attempt millisecond resolution using a command called outside a given process. The overhead of fork()'ing and exec()'ing the new process will completely mask any millisecond resolution that you are trying to capture. You really have to build the metrics into your application.
If it ain't broke, I can fix that.
Paddy_1
Valued Contributor

Re: how to get milli-second

Use this Java code to yield systtime you want


public class TimeZoneClock {
public static void main(String[] args) {
long nowMillis = System.currentTimeMillis();
System.out.println("current time in milliseconds: " + nowMillis);

Calendar cal = Calendar.getInstance();
System.out.println("Default TimeZone: " + cal.getTimeZone().getDisplayName() + " - " + cal.getTimeZone().getID());
System.out.println();

cal.setTime(new Date(nowMillis));
System.out.println("default TimeZone: " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND));
System.out.println();

cal.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
System.out.println("America/Los_Angeles: " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND));
System.out.println();

cal.setTimeZone(TimeZone.getTimeZone("America/Phoenix"));
System.out.println("America/Phoenix: " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND));
System.out.println();

cal.setTimeZone(TimeZone.getTimeZone("America/Denver"));
System.out.println("America/Denver: " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND));
System.out.println();

cal.setTimeZone(TimeZone.getTimeZone("America/Chicago"));
System.out.println("America/Chicago: " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND));
System.out.println();

cal.setTimeZone(TimeZone.getTimeZone("America/New_York"));
System.out.println("America/New_York: " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND));
System.out.println();
}
}
The sufficiency of my merit is to know that my merit is NOT sufficient
Paddy_1
Valued Contributor

Re: how to get milli-second

Forgot to add the headers :
------------------------
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
--------------------------

The sufficiency of my merit is to know that my merit is NOT sufficient
Gary Yu
Super Advisor

Re: how to get milli-second

thank you guys for the reply!

As Clay pointed out, either C of java, the overhead of forking process does count, so I may do it through pure programming language instead of scripts.

thanks,
Gary