Sponsored Content
Top Forums Shell Programming and Scripting Time in seconds on AIX 4.3.2.0 Post 302992534 by Don Cragun on Monday 27th of February 2017 05:49:36 AM
Old 02-27-2017
Quote:
Originally Posted by bakunin
Actually this is a solution:

Code:
date +'%T' | IFS=':' read hr min sec
time=$(( hr * 3600 + min * 60 + sec ))

This removes the necessity to use an external program (nawk, perl) and makes only use of standard (ksh-)features. Anyways, i am glad you have a solution that works.

I hope this helps.

bakunin
Hi bakunin,
The date +%T output gives you hours, minutes, and seconds (on a 24 hour clock) since midnight in the current timezone. The desired date +%s (which is not available on many UNIX systems, including AIX) gives you seconds since the Epoch (midnight at the start of January 1, 1970 UCT). You need a lot more information than what is provided by the current 24 hour clock time to convert that output to seconds since the Epoch.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

getting time in mili seconds

hi all UNIX Gurus, this is my first post...so i posting this with great expectations:o...hoping to get the similar replies... my question is.... need to get timestamp with millisecond in UNIX. Date command gives Year,month day, hour,minute and second but it does not give millisecond. Any... (5 Replies)
Discussion started by: Bhups
5 Replies

2. AIX

Unable to display the date-time in seconds on AIX

Hi, In unix the command "date +%s" displays the date-time in seconds since â00:00:00 1970-01-01 UTCâ (a GNU extension) when executed on unix: -sh-2.05b$ date +%s 1152092690 I tried with all the format control output but unable to display the date-time in seconds i,e as in unix format. Can... (6 Replies)
Discussion started by: me_haroon
6 Replies

3. Shell Programming and Scripting

how to display time in minutes n seconds...

Hi all, may i know how to display time in minutes and seconds(may be milliseconds and even smaller that ) in shell scripts.... (1 Reply)
Discussion started by: santy
1 Replies

4. UNIX for Advanced & Expert Users

Time Difference in seconds

It is required to calculate time difference in seconds between epoch time (19700101 00:00:00) and any given date time (e.g. 20010214 14:30:30). Is there any command in unix to get it? Thanks in adv. (1 Reply)
Discussion started by: k_bijitesh
1 Replies

5. Shell Programming and Scripting

File creation time in seconds

Hi All, Cany any one help me in solving this.. Problem statement: I have a requirement to find the time from which there are no files created in a given directory. For this I am assuming that I need to get the file creation time in seconds, then the current time in seconds using `date +%s`.... (7 Replies)
Discussion started by: chary
7 Replies

6. Shell Programming and Scripting

Time difference in seconds

date1=$(date +"%H:%M:%S") date2=$(date +"01:00:54") diff=$date2-$date1 echo $diff How to get the time difference in seconds. (4 Replies)
Discussion started by: sandy1028
4 Replies

7. Shell Programming and Scripting

Get Current Time in Seconds Perl

hi guys, i need to know how to get the current date/time in seconds and i want to be able to do this in a one liner. like say for instance, if want to get what the time is right now, i'll issue a command like this: ## perl -e ' print scalar(localtime(time + 0)), "\n"' Tue Jul 13 17:45:50... (4 Replies)
Discussion started by: SkySmart
4 Replies

8. Shell Programming and Scripting

Elapsed time in seconds in awk

I am trying to get the ellapsed time in seconds in the body of the awk script. I use unix date to get the time. It works in BEGIN {} but not in the body {} of awk. Any ideas? $ cat a BEGIN { "date +%s" | getline x print x } { "date +%s" | getline y print y } $ echo "one line" |... (3 Replies)
Discussion started by: arturas123
3 Replies

9. Shell Programming and Scripting

Get how much time process has been running in seconds

I use this command to get the time elapsed for a process ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time | grep perl It gives in format 19990 0.0 0.0 user /usr/bin/php 5-09:58:51 /usr/bin/php I need in seconds. Please use CODE tags for sample input and output as well... (2 Replies)
Discussion started by: anil510
2 Replies

10. Shell Programming and Scripting

Converting seconds to time

I have a list of time spans in seconds, and want to compute the time span as hh:mm:nn I am coding in bash and have coded the following. However, the results are wrong as "%.0f" rounds the values. Example: ftm: 25793.5 tmspan(hrs,min,sec): 7.16 429.89 25793.50 hh: 7 mm: 10 ss:... (2 Replies)
Discussion started by: kristinu
2 Replies
CTIME(2)							System Calls Manual							  CTIME(2)

NAME
ctime, localtime, gmtime, asctime, timezone - convert date and time to ASCII SYNOPSIS
#include <u.h> #include <libc.h> char* ctime(long clock) Tm* localtime(long clock) Tm* gmtime(long clock) char* asctime(Tm *tm) /env/timezone DESCRIPTION
Ctime converts a time clock such as returned by time(2) into ASCII (sic) and returns a pointer to a 30-byte string in the following form. All the fields have constant width. Wed Aug 5 01:07:47 EST 1973 Localtime and gmtime return pointers to structures containing the broken-down time. Localtime corrects for the time zone and possible day- light savings time; gmtime converts directly to GMT. Asctime converts a broken-down time to ASCII and returns a pointer to a 30-byte string. typedef struct { int sec; /* seconds (range 0..59) */ int min; /* minutes (0..59) */ int hour; /* hours (0..23) */ int mday; /* day of the month (1..31) */ int mon; /* month of the year (0..11) */ int year; /* year A.D. - 1900 */ int wday; /* day of week (0..6, Sunday = 0) */ int yday; /* day of year (0..365) */ char zone[4]; /* time zone name */ } Tm; When local time is first requested, the program consults the timezone environment variable to determine the time zone and converts accord- ingly. (This variable is set at system boot time by init(8).) The timezone variable contains the normal time zone name and its difference from GMT in seconds followed by an alternate (daylight) time zone name and its difference followed by a newline. The remainder is a list of pairs of times (seconds past the start of 1970, in the first time zone) when the alternate time zone applies. For example: EST -18000 EDT -14400 9943200 25664400 41392800 57718800 ... Greenwich Mean Time is represented by GMT 0 SOURCE
/sys/src/libc/9sys SEE ALSO
date(1), time(2), init(8) BUGS
The return values point to static data whose content is overwritten by each call. Daylight Savings Time is ``normal'' in the Southern hemisphere. These routines are not equipped to handle non-ASCII text, and are provincial anyway. CTIME(2)
All times are GMT -4. The time now is 10:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy