Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to generate milliseconds time stamp in Unix

1,587 views
Skip to first unread message

nickl...@gmail.com

unread,
May 28, 2013, 1:51:56 PM5/28/13
to
Hi,

I am trying to capture system time up to milliseconds from Unix and I am using HP-UX 11.31. It seems to me that Unix date command doesn't have the millsecond precision or I may not be doing something correctly.

I would be very grateful for any advice.

Thanks in advance.

Nick

Dan Espen

unread,
May 28, 2013, 2:05:02 PM5/28/13
to
Not a shell question, you'd do better on an HPUX forum.

Try reading this page:

http://h21007.www2.hp.com/portal/download/files/unprot/stk/tru64_stk/impacts/i389.html

<http://tinyurl.com/ojp6g42>

You'll get an idea about why the resolution you are seeing is limited.


--
Dan Espen

Janis Papanagnou

unread,
May 29, 2013, 5:24:39 AM5/29/13
to
GNU date seems to support that:

$ date -Ins
2013-05-29T11:13:13,718170300+0200

Though, you may not have it or not be allowed to install it? And
it may behave differently WRT this option on your HP platform; the
acuracy (ms, 盜, ns) may not be supported to the degree you need.
Probably worth a try anyway.

Janis

>
> Thanks in advance.
>
> Nick
>

Bill Marcum

unread,
May 29, 2013, 2:16:55 PM5/29/13
to
On 05/29/2013 05:24 AM, Janis Papanagnou wrote:
> Am 28.05.2013 19:51, schrieb nickl...@gmail.com:
>> Hi,
>>
>> I am trying to capture system time up to milliseconds from Unix and I
>> am using HP-UX 11.31. It seems to me that Unix date command doesn't
>> have the millsecond precision or I may not be doing something
>> correctly.
>>
>> I would be very grateful for any advice.
>
> GNU date seems to support that:
>
> $ date -Ins
> 2013-05-29T11:13:13,718170300+0200
>
That's interesting. The man page, info and 'date --help' don't show a
-Ins option, but it is accepted. (coreutils 8.13, Ubuntu 12.04).
'+%N' is documented to show time in nanoseconds.


Luuk

unread,
May 29, 2013, 3:37:59 PM5/29/13
to
The data--help DOES show this in 8.17, see below:

luuk@opensuse:~> date --version
date (GNU coreutils) 8.17
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.
luuk@opensuse:~> date -I?
date: invalid argument ‘?’ for ‘--iso-8601’
Valid arguments are:
- ‘hours’
- ‘minutes’
- ‘date’
- ‘seconds’
- ‘ns’
Try 'date --help' for more information.
luuk@opensuse:~>

Stephane Chazelas

unread,
May 29, 2013, 5:08:07 PM5/29/13
to
2013-05-28 10:51:56 -0700, nickl...@gmail.com:
> Hi,
>
> I am trying to capture system time up to milliseconds from Unix and I am using HP-UX 11.31. It seems to me that Unix date command doesn't have the millsecond precision or I may not be doing something correctly.
>
> I would be very grateful for any advice.
[...]

Recent versions of the zsh and ksh93 shells can have a floating
point $SECONDS variable. And floating point date functions:

zsh$ typeset -F SECONDS=0; sleep 1; echo $SECONDS
1.0038030000
zsh$ zmodload zsh/datetime
zsh$ echo $EPOCHREALTIME
1369861114.6814498901

ksh93$ typeset -F SECONDS=0; sleep 1; echo "$SECONDS"
1.0012488365
ksh93$ printf '%(%.9s)T\n' now
1369861561.684708000
ksh93$ printf '%(%F %T.%N)T\n' now
2013-05-29 22:07:23.540861000

--
Stephane

Dan Espen

unread,
May 29, 2013, 5:34:47 PM5/29/13
to
Stephane Chazelas <stephane...@gmail.com> writes:

> 2013-05-28 10:51:56 -0700, nickl...@gmail.com:
>> Hi,
>>
>> I am trying to capture system time up to milliseconds from Unix and
>> I am using HP-UX 11.31. It seems to me that Unix date command
>> doesn't have the millsecond precision or I may not be doing
>> something correctly.
>>
>> I would be very grateful for any advice.
> [...]
>
> Recent versions of the zsh and ksh93 shells can have a floating
> point $SECONDS variable. And floating point date functions:

None of this changes what the hardware is doing.
CPU time of day clocks sometimes don't update with high resolution.
I'm familiar with clocks that have bits down into the micro or nano second range
but don't update nearly that often.


From this page:

http://h21007.www2.hp.com/portal/download/files/unprot/hpux/HowToTellTheTime.pdf

Check the chart on page 8 to see what the precision supplied by various
system calls.

As I said, shell issues aside, you need to know what the hardware and
HPUX are going to give you.

--
Dan Espen

David W. Hodgins

unread,
May 29, 2013, 2:35:20 PM5/29/13
to
I didn't see it at first glance either, but it's there ...
-I[TIMESPEC], --iso-8601[=TIMESPEC]
output date/time in ISO 8601 format. TIMESPEC=`date' for date only (the
default), `hours', `minutes', `seconds', or `ns' for date and time to the
indicated precision.

Regards, Dave Hodgins

--
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)

Thomas 'PointedEars' Lahn

unread,
May 29, 2013, 9:15:04 PM5/29/13
to
David W. Hodgins wrote:

> Bill Marcum wrote:
>> On 05/29/2013 05:24 AM, Janis Papanagnou wrote:
>>> GNU date seems to support that:
>>> $ date -Ins
>>> 2013-05-29T11:13:13,718170300+0200
>>
>> That's interesting. The man page, info and 'date --help' don't show a
>> -Ins option, but it is accepted. (coreutils 8.13, Ubuntu 12.04).
>> '+%N' is documented to show time in nanoseconds.
>
> I didn't see it at first glance either, but it's there ...
> -I[TIMESPEC], --iso-8601[=TIMESPEC]
> output date/time in ISO 8601 format. TIMESPEC=`date'
> for date only (the
> default), `hours', `minutes', `seconds', or `ns' for date
> and time to the indicated precision.

In the GNU coreutils 8.12.197-032bb man page for date(1) 8.13 (September
2011), there is

| --rfc-3339=TIMESPEC
| output date and time in RFC 3339 format. TIMESPEC=`date',
| `seconds', or `ns' for date and time to the indicated
| precision. Date and time components are separated by a
| single space: 2006-08-07 12:34:56-06:00

and there is no mention of the “-I” option there or in the TeXinfo pages,
although the date(1) from the same Debian GNU/Linux package also supports
“-Ins” as described.

--
PointedEars
0 new messages