LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 05-14-2008, 01:45 AM   #1
as400
Member
 
Registered: Apr 2004
Location: USA
Distribution: Solaris 10 (x86) and Windows XP Pro SP2
Posts: 596

Rep: Reputation: 30
Changing the Time Format in Solaris 10?


Hi,

This is a stupid question, but I have been working with OpenVMS systems in the past, and VMS logs times in this format below:
HH:MM:SS:00

In UNIX, how can I add the time format were the time shows in CENTISECONDS like the one in above? For example, I want all applications including the time in which users logged on in the format as below:

12:00:59.75

I have a gut feeling that this is impossible to do in UNIX, but I hiope somebody has some ideas.

Thx.
 
Old 05-14-2008, 08:29 PM   #2
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
Hey there,

I'm not sitting in front of a Sol 10 server right now, but I think you're correct in your assumption. You can set the date as root using the "date" command.

Check the manpage for the date command to see how specific you can get, but I believe it's only down to the second. I could be wrong, though. Hopefully, so

Best wishes,

Mike
 
Old 05-15-2008, 12:00 AM   #3
as400
Member
 
Registered: Apr 2004
Location: USA
Distribution: Solaris 10 (x86) and Windows XP Pro SP2
Posts: 596

Original Poster
Rep: Reputation: 30
Hi, thanks. Im not on my laptop now which has Solaris running, but I will check it out later.
I know how to work with the basic date commands.

So, if I wanted to add the CENTISECONDS format, its done like this???

For example: 12:45:00.00

# 12450000

Just for trying it out, what value should I try out?
 
Old 05-15-2008, 12:19 AM   #4
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
Bummer,

I had to do some work tonight and logged into one of our sol 10 boxes and it looks like date is only accurate (or displayable) to the second. I ran date with -x just to get the usage output.

Quote:
root # uname -rv
5.10 Generic_127111-09
root # date -x
date: illegal option -- x
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
I've always thought this was strange, since "time" does display microseconds when you measure actions.

Sorry I can't help you out with that

Maybe there's a custom package out there for this ???

Best wishes,

Mike
 
Old 05-15-2008, 12:20 AM   #5
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
Sorry - I didn't reply to your question

The safest thing to do if you want to permanently change just the time is do this as root:

time 160403

for 4:04pm and 3 seconds.

, Mike
 
Old 05-15-2008, 12:32 AM   #6
as400
Member
 
Registered: Apr 2004
Location: USA
Distribution: Solaris 10 (x86) and Windows XP Pro SP2
Posts: 596

Original Poster
Rep: Reputation: 30
Thanks alot for your efforts.

It looks like only VMS boxes do that.

Even the large scale Mainframes stamps time only to the second also....
 
Old 05-15-2008, 07:24 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Here is a C program that will give you microsecond resolution timestamp:
Code:
#include <sys/time.h>
main()
{
  char ct[28];
  struct timeval tv;
  gettimeofday(&tv, NULL);
  sprintf(ct, "%s", ctime(&tv.tv_sec));
  printf("%19.19s.%06ld %4.4s\n",ct ,tv.tv_usec, &ct[20]);
  exit(0);
}
Code:
Fri May 16 02:24:34.362967 2008
 
Old 05-15-2008, 08:49 PM   #8
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
Sweet,

Make that an alias for "date" (or make it a whole separate command) and you've got yourself a winner. I tested it out and it looks great.

Quote:
$ ./c
Thu May 15 20:47:37.608412 2008
Thanks for the hook-up jlliagre

, Mike
 
Old 05-23-2008, 12:06 AM   #9
as400
Member
 
Registered: Apr 2004
Location: USA
Distribution: Solaris 10 (x86) and Windows XP Pro SP2
Posts: 596

Original Poster
Rep: Reputation: 30
Hi,

Now, where can I put this source code??? Into which directory? Or, is this a command?

Thx.
 
Old 05-23-2008, 01:35 AM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by as400 View Post
Into which directory?
Your home directory or a subdir there.
Quote:
Or, is this a command?
Once compiled, yes:

Code:
/usr/sfw/bin/gcc datems.c -o datems
 
Old 05-23-2008, 01:44 AM   #11
as400
Member
 
Registered: Apr 2004
Location: USA
Distribution: Solaris 10 (x86) and Windows XP Pro SP2
Posts: 596

Original Poster
Rep: Reputation: 30
YOur going to have to explain on how to do this.

Do I have to copy and paste that code into a Text Editor and save it to my home directory and then after that I can run that command?
 
Old 05-23-2008, 02:01 AM   #12
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
That's it. Save the new file as "datems.c" which would mean date milli/micro seconds.

To run the command, use "./datems" or copy it to /usr/bin and simply run "datems".

Note that this command isn't going to change the way system timestamps are displayed. It just demonstrates that Solaris/Unix/Linux can provide sub-second timestamps like or better than VMS.

I have no doubt mainframes can do it too.
 
Old 05-23-2008, 02:54 AM   #13
as400
Member
 
Registered: Apr 2004
Location: USA
Distribution: Solaris 10 (x86) and Windows XP Pro SP2
Posts: 596

Original Poster
Rep: Reputation: 30
So, after this, will my clock on the CDE Desktop update the time in milliseconds or only when I do the date command?

And do I have to copy and paste the source that you posted into GEDIT and the save it as "datems.c" and then put I have to put this into the /HOME directory?
Thanks alot.

Last edited by as400; 05-23-2008 at 03:08 AM.
 
Old 05-23-2008, 03:20 AM   #14
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by as400 View Post
So, after this, will my clock on the CDE Desktop update the time in milliseconds
Your clock isn't updating the time, it just displays it.
Quote:
or only when I do the date command?
Same as the above. the date and clock only display the time with one second precision.
Quote:
And do I have to copy and paste the source that you posted into GEDIT and the save it as "datems.c" and then put I have to put this into the /HOME directory?
Yes, in your $HOME directory precisely, then run the gcc command I wrote in a terminal emulator window.
 
Old 11-13-2008, 11:11 AM   #15
unixmail
LQ Newbie
 
Registered: Nov 2008
Posts: 1

Rep: Reputation: 0
When I run it, I am getting below errors:

./micro.c
./micro.c: line 6: syntax error near unexpected token `&'
./micro.c: line 6: ` gettimeofday(&tv, NULL);'

This is what the program looks like - I have named it as micro.c:
#include <sys/time.h>
main()
{
char ct[28];
struct timeval tv;
gettimeofday(&tv, NULL);
sprintf(ct, "%s", ctime(&tv.tv_sec));
printf("%19.19s.%06ld %4.4s\n",ct ,tv.tv_usec, &ct[20]);
exit(0);
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loging into Solaris for 1st time and changing default multiboot OS to windows Some Guy Solaris / OpenSolaris 5 05-04-2007 12:42 PM
Time format in boot-time messages jonr Linux - Kernel 1 12-22-2006 12:31 PM
Changing distro - how do I format Root ? dms05 Linux - Newbie 2 05-30-2006 08:20 AM
Downloading Solaris 10 and wondering how to format my HD! cereal83 Solaris / OpenSolaris 9 02-28-2005 02:18 PM
Changing Keyboard input into UTF-8 format LinuxTiro Programming 1 05-08-2004 09:29 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 10:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration