07-14-2006
epoch time (for UNIX) is given as the number of seconds elapsed since 00:00:00 January 1, 1970. It can be converted to all kinds of formats.
Show us one of your data items.
To answer your question - if they are in a format that looks like this: 1152692657
then they are in the primary format. Subtract first, then convert. Otherwise, convert to seconds elapsed since Jan 1 1970, then subtract, then convert back to elapsed time.
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Guys, i have a question...
I have 2 sets of data say "a" and "a+1" which has values in epoch time..
Question is... if i were to get the time difference where diff = "a+1" - "a"
can i convert it back to real time duration after the subtraction...
OR i need to convert em first before i do the... (2 Replies)
Discussion started by: 12yearold
2 Replies
2. Shell Programming and Scripting
Hi,
i need to convert below date/time format into epoch time
YYYY-m-d H:M
below the example:
a=`date +"%F %H:%M"`
echo $a
Convert $a to epoch time
------------------------------------------------------------------------
lets take an example
if $a=1.03
here i want the epoch time... (3 Replies)
Discussion started by: ali560045
3 Replies
3. Shell Programming and Scripting
I have a file named "suspected" with series of line like these :
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies
4. Shell Programming and Scripting
Hi guys,
I know that this topic has been discuss numerous times, and I have search the net and this forum for it.
However, non able to address the problem I faced so far.
I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies
5. Shell Programming and Scripting
Hi,
Is there any easy way to convert date time(stored in shell variable ) to epoch time in solaris box? As +%s is working on linux but not on solaris, also -d option is not working.
Any suggestion please? (6 Replies)
Discussion started by: anshuman0507
6 Replies
6. Shell Programming and Scripting
Hi all,
I got a file with epoch times like this.
1264010700
1264097400
1263529800
1263762900
1263924300
What I want.
I want all epoch times which are > current epoch time written to a file. So everything that is < will be ignored and not written to the file.
Thanks (3 Replies)
Discussion started by: stinkefisch
3 Replies
7. Shell Programming and Scripting
Dear experts,
I have an epoch time input file such as : -
1302451209564
1302483698948
1302485231072
1302490805383
1302519244700
1302492787481
1302505299145
1302506557022
1302532112140
1302501033105
1302511536485
1302512669550
I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies
8. Solaris
One way of getting epoch time in solaris is
truss date 2>&1 | awk '/^time/{print $3}'
Is there any other simple command that can be run from Korn Shell to display epoch time in solaris 5.10? (3 Replies)
Discussion started by: indianya
3 Replies
9. Shell Programming and Scripting
# 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)
Discussion started by: vivek d r
3 Replies
10. Shell Programming and Scripting
I have a list of epoch times delimited by "-" as follows:
1335078000 - 1335176700
1335340800 - 1335527400
1335771300 - 1335945600
1336201200 - 1336218000
The corresponding dates are:
20120422 1000 - 20120423 1325
20120425 1100 - 20120427 1450
20120430 1035 - 20120502 1100 ... (3 Replies)
Discussion started by: alex2005
3 Replies
LEARN ABOUT NETBSD
timespec_to_timeval
TIMEVAL(3) BSD Library Functions Manual TIMEVAL(3)
NAME
timeval, timespec, itimerval, itimerspec, bintime -- time structures
SYNOPSIS
#include <sys/time.h>
void
TIMEVAL_TO_TIMESPEC(struct timeval *tv, struct timespec *ts);
void
TIMESPEC_TO_TIMEVAL(struct timeval *tv, struct timespec *ts);
DESCRIPTION
The <sys/time.h> header, included by <time.h>, defines various structures related to time and timers.
1. The following structure is used by gettimeofday(2), among others:
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
The tv_sec member represents the elapsed time, in whole seconds. The tv_usec member captures rest of the elapsed time, represented as
the number of microseconds.
2. The following structure is used by nanosleep(2), among others:
struct timespec {
time_t tv_sec;
long tv_nsec;
};
The tv_sec member is again the elapsed time in whole seconds. The tv_nsec member represents the rest of the elapsed time in nanosec-
onds.
A microsecond is equal to one millionth of a second, 1000 nanoseconds, or 1/1000 milliseconds. To ease the conversions, the macros
TIMEVAL_TO_TIMESPEC() and TIMESPEC_TO_TIMEVAL() can be used to convert between struct timeval and struct timespec.
3. The following structure is used by setitimer(2), among others:
struct itimerval {
struct timeval it_interval;
struct timeval it_value;
};
4. The following structure is used by timer_settime(2), among others:
struct itimerspec {
struct timespec it_interval;
struct timespec it_value;
};
Both struct itimerval and struct itimerspec are used to specify when a timer expires. Generally, it_interval specifies the period
between successive timer expirations. A value zero implies that the alarm will fire only once. If it_value is non-zero, it indicates
the time left to the next timer expiration. A value zero implies that the timer is disabled.
5. The following structure is used by bintime(9), among others:
struct bintime {
time_t sec;
uint64_t frac;
};
The sec member specifies the time in seconds and frac represents a 64-bit fraction of seconds. The struct bintime is meant to be used
in the kernel only. It is further described in timecounter(9).
EXAMPLES
It can be stressed that the traditional UNIX timeval and timespec structures represent elapsed time, measured by the system clock (see
hz(9)). The following sketch implements a function suitable for use in a context where the timespec structure is required for a conditional
timeout:
static void
example(struct timespec *spec, time_t minutes)
{
struct timeval elapsed;
(void)gettimeofday(&elapsed, NULL);
_DIAGASSERT(spec != NULL);
TIMEVAL_TO_TIMESPEC(&elapsed, spec);
/* Add the offset for timeout in minutes. */
spec->tv_sec = spec->tv_sec + minutes * 60;
}
A better alternative would use the more precise clock_gettime(2).
SEE ALSO
timeradd(3), tm(3), bintime_add(9)
BSD
April 12, 2011 BSD