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

Timestamp conversion from UTC to Epoch ?

0 views
Skip to first unread message

Sonja Streuber

unread,
Mar 3, 2004, 9:33:35 PM3/3/04
to
Hi there!
I am trying to convert a UTC timestamp into an Epoch timestamp, so
that I can do date math. Looks like there's no option for the `date`
command to do that, and I haven't been lucky with `calendar`, either.
Does anyone have an idea how to do this on AIX 4.3.3?
Thanks.

Sonja

Alberto 'JCN-9000' Varesio

unread,
Mar 4, 2004, 4:15:58 AM3/4/04
to

Old but maybe useful post I archived

Matthew Landt <.....@ibm.com> wrote:

Here is a method that was posted a while ago. I took that function
and added my formatting and abiltiy to change for a couple of date
formats. I already uncommented the format you suggest.

- Matt

#!/bin/ksh
###########################################################################
# Date calculations using Korn shell (ksh88)
# Tapani Tarvainen July 1998, May 2000
# This code is in the public domain.
# Julian Day Number from calendar date
date2julian() # day month year
{
typeset -i day month year tmpmonth tmpyear
day=$1; month=$2; year=$3
((tmpmonth = 12 * year + month - 3))
((tmpyear = tmpmonth / 12))
print $(( (734 * tmpmonth + 15) / 24 - 2 * tmpyear + \
tmpyear/4 - tmpyear/100 + tmpyear/400 + day + 1721119 ))
}

###
# Matt's Added formatting
###

# Store input dates
date1=$1
date2=$2

# Get the dates into their respective fields. Uncomment the format of
# date input being used.

# YYYYMMDD
#year1=${date1%????}
# mmdd1=${date1#????}
# month1=${mmdd1%??}
# day1=${mmdd1#??}
#year2=${date2%????}
# mmdd2=${date2#????}
# month2=${mmdd2%??}
# day2=${mmdd2#??}

# YYYY/MM/DD or YYYY/M/D
#print $date1 |IFS=/ read year1 month1 day1
#print $date2 |IFS=/ read year2 month2 day2

# MM/DD/YY or M/D/YYYY
#print $date1 |IFS=/ read month1 day1 year1
#print $date2 |IFS=/ read month2 day2 year2

# DD/MM/YY or M/D/YYYY
print $date1 |IFS=/ read day1 month1 year1
print $date2 |IFS=/ read day2 month2 year2

# Calculate and print the difference between dates (date2 - date1)
print -- "$(($(date2julian $day2 $month2 $year2) -
$(date2julian $day1 $month1 $year1)))"


--
Alberto 'JCN-9000' Varesio AKA BlueRider AIX pSeries System Admin
Datavision PLM - Tel: +390117710276 Biker on HONDA CB500 - LHG
http://www.datavisionplm.com Jeeper on Sport TJ - Wave
Please http://www.fsf.org/philosophy/no-word-attachments.html, thanks!
==
BOFH Excuse: We already sent around a notice about that.

mark taylor

unread,
Mar 4, 2004, 5:14:55 AM3/4/04
to
shstr...@verbalicon.com (Sonja Streuber) wrote in message news:<98f12853.04030...@posting.google.com>...

gnudate +'%s' will give current epoch seconds, is this what you want
? you could use perl Time::Local 'timelocal_nocheck' can also do the
calculations for you if you want to convert the output of the ls -l
command or a TSM backup timestamp etc... check out the docs.

Rgds
Mark Taylor

Bill

unread,
Mar 4, 2004, 9:46:15 AM3/4/04
to
shstr...@verbalicon.com (Sonja Streuber) wrote in message news:<98f12853.04030...@posting.google.com>...

perl -we "print time"
1078411396

bc
1078411396+86400
1078497796

perl -we "print scalar localtime 1078411396"
Thu Mar 4 08:43:16 2004

perl -we "print scalar localtime 1078497796"
Fri Mar 5 08:43:16 2004

I have some standalone "C" programs I created years ago to do this,
but I use perl now where possible.

BV

0 new messages