Try looking at the man page for your implementation of the date command.
On a Linux system, you can get (for example) the number of seconds from the epoch like this:
Or if you want the date yesterday in YYYYMMDD format, you can do this: Note: the --date option is specific to GNU date, as far as I know, and is not portable...
If you have any other questions about date handling, please respond, as I have been doing a lot of tedious date juggling in scripts lately.
If you do reply, please include your operating system (available via the uname -a command), and if possible, which "date" you are using. Also, please give examples of which formats you are converting from, and the expected output.
Hi
I need help to do some calculation in script.
I have a monitor program (munin) that I would like to log uptime information from a server.
The script looks like this (not complete):
#!/bin/sh
# server_uptime
### Config Start
# Reads the server parameters using the HTTP port with... (7 Replies)
Hello,
I have an AIX 5.3 system and i created a script to get the last login of users.
The script goes like this:
LAST_LOGIN=`lsuser -a time_last_login $cur_user`
TIME_LOGIN=`perl -e 'print scalar localtime("$LAST_LOGIN")'`
Actually what i do in these two lines is to set a variable... (2 Replies)
Hi,
Thanks bartus11 yesterday's code worked fine for me.
In meantime I've found another "issue".
As you can see highlighted, the time format in my original input in case of two rows which should be duplicited ,is differentwhat I need to do is to convert to this format "20110607-08:03:22"... (4 Replies)
I can not find a working script or way to do this on sun solaris , can someone please guide me?
e.g 1327329935 epoch secs = 012312 (ddmmyy)
thanks (5 Replies)
I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk.
I tried
This is how each line of the file looks like, different date and time in this format
Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th
... (2 Replies)
# date +%s -d "Mon Feb 11 02:26:04"
1360567564
# perl -e 'print scalar localtime(1360567564), "\n";'
Mon Feb 11 02:26:04 2013
the epoch conversion is working fine. but one of my application needs 13 digit epoch time as input
1359453135154
rather than 10 digit epoch time 1360567564... (3 Replies)
I have a Raspberry Pi that logs some temperatures using Onewire. Data is collected with RRDTool.
The command sudo rrdtool fetch ute_temp.rrd AVERAGE -s -1h > ./test.log
and then cat test.log gives the result
1388608500: 2.3579639836e+00
.
How do I write a script that converts the Epoch time... (4 Replies)
I am trying to create a script that will take epoch (input from command line) and convert it into a readable format in bash/shell
---------- Post updated at 08:03 PM ---------- Previous update was at 07:59 PM ----------
#!bin/bash
read -p "Please enter a number to represent epoch time:"... (9 Replies)
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)
Hello,
How can we convert date like format 20181004171050 in seconds ?
I can able to convert till date but failing for HHMMSS.
date -d "20181004" "+%s" output as 1538596800 .
But when i add hhmmss it is failing date -d "20181004172000" "+%s" result Invalid date
Kindly guide.
Regards (16 Replies)
Discussion started by: sadique.manzar
16 Replies
LEARN ABOUT POSIX
ctime_r
CTIME(P) POSIX Programmer's Manual CTIME(P)
NAME
ctime, ctime_r - convert a time value to a date and time string
SYNOPSIS
#include <time.h>
char *ctime(const time_t *clock);
char *ctime_r(const time_t *clock, char *buf);
DESCRIPTION
For ctime(): The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements
described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers to the ISO C standard.
The ctime() function shall convert the time pointed to by clock, representing time in seconds since the Epoch, to local time in the form of
a string. It shall be equivalent to:
asctime(localtime(clock))
The asctime(), ctime(), gmtime(), and localtime() functions shall return values in one of two static objects: a broken-down time structure
and an array of char. Execution of any of the functions may overwrite the information returned in either of these objects by any of the
other functions.
The ctime() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe.
The ctime_r() function shall convert the calendar time pointed to by clock to local time in exactly the same form as ctime() and put the
string into the array pointed to by buf (which shall be at least 26 bytes in size) and return buf.
Unlike ctime(), the thread-safe version ctime_r() is not required to set tzname.
RETURN VALUE
The ctime() function shall return the pointer returned by asctime() with that broken-down time as an argument.
Upon successful completion, ctime_r() shall return a pointer to the string pointed to by buf. When an error is encountered, a null pointer
shall be returned.
ERRORS
No errors are defined.
The following sections are informative.
EXAMPLES
None.
APPLICATION USAGE
Values for the broken-down time structure can be obtained by calling gmtime() or localtime(). The ctime() function is included for compati-
bility with older implementations, and does not support localized date and time formats. Applications should use the strftime() function
to achieve maximum portability.
The ctime_r() function is thread-safe and shall return values in a user-supplied buffer instead of possibly using a static data area that
may be overwritten by each call.
RATIONALE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
asctime() , clock() , difftime() , gmtime() , localtime() , mktime() , strftime() , strptime() , time() , utime() , the Base Definitions
volume of IEEE Std 1003.1-2001, <time.h>
COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol-
ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE
and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained
online at http://www.opengroup.org/unix/online.html .
IEEE /The Open Group 2003 CTIME(P)