Get timestamp with millisecond precision


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get timestamp with millisecond precision
# 1  
Old 06-06-2012
Get timestamp with millisecond precision

Hi All,

could any body let me know.
how to get timestamp with millisecond precision in unix bash shell.
example -->2005-12-06- 4-22-35-195

please help me.

Thanks,
KrupaSmilie
# 2  
Old 06-06-2012
If you have Linux:
Code:
date --rfc-3339=ns
date +%Y-%m-%d:%H:%M:%S.%N

gives nanosecond accuracy, you can truncate the value to ms if you want.
# 3  
Old 06-07-2012
Hi,
I am getting below error

Code:
[csdwmast@ucdoud01]:../to_be_loaded>`date +%Y-%m-%d:%H:%M:%S.%N`
ksh: 2012-06-06:10:18:01.%N:  not found

Thanks,
Krupa

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.


---------- Post updated at 11:50 PM ---------- Previous update was at 09:20 AM ----------

Hi Jim,

when i am using this command in unix prompt.

Code:
`date +%Y-%m-%d:%H:%M:%S.%N`

I am getting blow error.

ksh: 2012-06-06:10:18:01.%N: not found

please help me regarding this.

Thanks,
Krupa
# 4  
Old 06-07-2012
Code:
$ perl -le 'use POSIX 'strftime'; use Time::HiRes 'gettimeofday'; ($x,$y)=gettimeofday; $y=sprintf("%03d",$y/1000);print strftime("%Y-%m-%d %H:%M:%S",localtime($x)),".$y"'
2012-06-07 06:07:06.002
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Subtract millisecond Timestamps with awk

Hello, am not able to subtract timestamps in milliseconds. I extract the timestamp as a string, and then try to subtract the two, but since it is a string, system just outputs 0 awk -F"," 'substr($1,0,13) - substr($2,0,013)' File where $1 and $2 are the timestamps in the format... (4 Replies)
Discussion started by: sidnow
4 Replies

2. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

3. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

4. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

5. Shell Programming and Scripting

Precision in print

I have a shell script which prints a variable to a text file (sorry if this is the wrong terminology, I'm new to this): awk `{sumdiffsqt+=$1;stdevt=sqrt(sumdiffsqt/('${n}'-1));errt=stdevt/sqrt('${n}')} END {print '$period',stdevt,errt}' diffsqt.txt >> ${xstation1}_${xstation2}_tt.err I need... (4 Replies)
Discussion started by: claire.a
4 Replies

6. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

7. Programming

max precision in float

Hi, As all of us know that size of int is machine as well as compiler dependent we can get the range and size of an int , float and char etc in /usr/include/limits.h header file of a compiler but could any one tell me how to get info of precision of float and ... (6 Replies)
Discussion started by: useless79
6 Replies

8. Shell Programming and Scripting

How to find date Difference in AWK/GAWK with millisecond precision

Hi, I have a log file that has the date in this format "2006-05-30_13:14:04,256". I need to find the time difference between two log entries in milliseconds. How to achieve this in AWK/GAWK script? :confused: (2 Replies)
Discussion started by: omprasad
2 Replies

9. Programming

Help! Display Time with Millisecond

Hi All, Urgent! Just a newbie needing advice. Has anybody have a sample C script code in Unix to display time with milliseconds? Most of the research I'm doing is up to the seconds format only. Thanks! Leidail (3 Replies)
Discussion started by: rezlez
3 Replies

10. UNIX for Dummies Questions & Answers

precision getting?

I need to find out the precision on a solaris machine using the unix terminal. How do I find this out? Specifics needed: How are single precision numbers represented (8 or 16 bit) How are double precision numbers represented (16 or 32 bit) How are they stored. ( some computers store numbers... (1 Reply)
Discussion started by: Townsfolk
1 Replies
Login or Register to Ask a Question