Sponsored Content
Full Discussion: get unix timestamp
Operating Systems AIX get unix timestamp Post 302127330 by kah00na on Tuesday 17th of July 2007 09:23:35 AM
Old 07-17-2007
Here's a korn shell way to do it. You'll have to add your timezone info near the bottom. I live in CST zone so I don't care about the others. Smilie

Code:
##*******************************************************************************
## Script       epoch
## Purpose      Take date in formatted string as an argument and coverts it
##              into epoch time (seconds since 1/1/1970)
## Usage        ./epoch Aug 25 23:59:59 2007 GMT
##===============================================================================
## History
## 2007/01/15  kah00na    Creation of script (some code from the internet)
##*******************************************************************************

year=$4
month=$1
day=$2
hour=$(echo $3 | cut -d: -f1)
min=$(echo $3 | cut -d: -f2)
sec=$(echo $3 | cut -d: -f3)
tz=$5

# Convert month to number
if [ $month = "Jan" ]; then
        month=1
elif [ $month = "Feb" ]; then
        month=2
elif [ $month = "Mar" ]; then
        month=3
elif [ $month = "Apr" ]; then
        month=4
elif [ $month = "May" ]; then
        month=5
elif [ $month = "Jun" ]; then
        month=6
elif [ $month = "Jul" ]; then
        month=7
elif [ $month = "Aug" ]; then
        month=8
elif [ $month = "Sep" ]; then
        month=9
elif [ $month = "Oct" ]; then
        month=10
elif [ $month = "Nov" ]; then
        month=11
elif [ $month = "Dec" ]; then
        month=12
fi

# leap days in past years
leapdays=$(( (year - 1969)/4 ))

# Is this year a leap year?
leap=$(( year % 4 == 0 ))

# Days in each month this year.
mdays[1]=31
mdays[2]=$((28+leap))
mdays[3]=31
mdays[4]=30
mdays[5]=31
mdays[6]=30
mdays[7]=31
mdays[8]=31
mdays[9]=30
mdays[10]=31
mdays[11]=30
mdays[12]=31

# days since the epoch, not counting earlier months this year
daycount=$(( (year - 1970) * 365 + leapdays + day - 1))

# Step through earlier months this year and add the days
m=$((month - 1))
while [ $m -ge 1 ]; do
        #echo "month=$m"
        daycount=$((daycount+${mdays[$m]} ))
        m=$((m-1))
done

# Now the seconds
epoch=$(( ( (daycount * 24 + hour) * 60 + min) * 60 + sec ))

# Add the time zones that apply to you
case "$tz" in
        #GMT) epoch=$((epoch + 0));;
        #EST) epoch=$((epoch + 18000));;
        CST) epoch=$((epoch + 21600));;
        #GMT) epoch=$((epoch + 21600));;
        #*)   epoch="ERROR: unrecognized on time zone";;
esac
echo "${epoch}"

EDIT: The "CODE" tags make the code look better. Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

display the timestamp of a server UNIX

I can't find the command shell UNIX to display the timestamp of the current date. It's not an option of the commande date. (3 Replies)
Discussion started by: nicolas
3 Replies

2. UNIX for Advanced & Expert Users

FTP from windows to Unix maintaining timestamp

Hi, Is it possible to Ftp the files from Windows to Unix while maintaining their timestamp Gaurav (1 Reply)
Discussion started by: gauravgoel
1 Replies

3. Programming

converting unix timestamp into readable format using c++

hi everyone, im new here and am in desperate need of help. I want to convert my 32 bit unix time stamp ' 45d732f6' into a readable format (Sat, 17 February 2007 16:53:10 UTC) using c++. I have looked around the interent but i just cant make sense of anything. All examples i can find just... (3 Replies)
Discussion started by: uselessprog
3 Replies

4. AIX

unix timestamp

hi, i have heard that date and time stamp are stored somewhere in unix as an interger. suppose May 20 07:05:59 is stored as 12342234 can anyone tell me where to find this integer. (9 Replies)
Discussion started by: ali560045
9 Replies

5. UNIX for Advanced & Expert Users

AIX/awk date to unix timestamp

Hello, I am inside a awk script on AIX, I am feeding to awk ls -luNR i need to convert ls -u time format "month day h:m/yr" to Unix epoch time, POSIX time, or aka unix timestamp I do not have strftime funk in my awk, and i have to do this fast meaning that I cannot do a system call in the... (1 Reply)
Discussion started by: nullwhat
1 Replies

6. UNIX for Dummies Questions & Answers

Unix timestamp to readable date

How would I convert a unix timestamp such as "1232144092" to a readable date such as "1/16/2009 10:14:28 PM" ? I thought I could use date, but I don't think so now.. Any help would be great!! (4 Replies)
Discussion started by: Rhije
4 Replies

7. Shell Programming and Scripting

TimeStamp to unix time

Hi, is there a way to get unix time from timestamp using date function in unix/ OS: SunOS 5.10 input : 2012-07-26 15:00:00 output: 1343314800Thanks in advance (6 Replies)
Discussion started by: sol_nov
6 Replies

8. Shell Programming and Scripting

Check if a string is a valid timestamp in UNIX.

Hi all, I have date and time value in a string, I want to check if it is a valid date and time. Need help on this. Thanks (7 Replies)
Discussion started by: Pratiksha Mehra
7 Replies

9. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

10. Shell Programming and Scripting

UNIX timestamp

Hi , I have files in s3 buckect under this directory(unix timestamp).I want to get the files on daily bases based batch date which is current unix date.Any help how to convert my unix date to unixtimestamp and get the files to local system.Any help would be great aws s3 ls... (18 Replies)
Discussion started by: mohan705
18 Replies
lunar(1)						      General Commands Manual							  lunar(1)

NAME
lunar (version 2.2) - a calendar conversion utility SYNTAX
lunar [ -h ] [ -b ] [ -i ] [ -l ] year month day [ hour ] DESCRIPTION
The program performs date conversion between the Gregorian Solar Calendar (SC) and the Chinese Lunar Calendar (LC). Given a date in either calendar, the program also outputs the corresponding "shengxiao" (animal of the year) and "ganzhi" characters. The date range currently covered is from about 1900 A.D. to 2049 A.D. For the sake of convenience, we choose the convention such that the solar and lunar year numbers of the first day of a lunar year are the same. For example, SC 1991.2.15 is LC 1991.1.1, while SC 1991.2.14 is LC 1990.12.30. Moreover, we choose the convention such that the solar and lunar hour numbers (in 24-hour clock) of a date are the same, although a lunar day starts at 23:00 of a solar day. This means that SC 1991.2.15.23 is LC 1991.1.2.23, while SC 1991.2.16.0 is LC 1991.1.2.0, and SC 1991.2.16.1 is LC 1991.1.2.1. The standard time of the Lunar Calendar is Beijing (Hong Kong) Standard Time, not GMT. Be sure to adjust appropriately for other time zones and "Daylight Saving Time". In the Lunar Calendar, a normal year has 12 months, and a leap year (run-nian) has 13 months, where the extra month is called a "leap month" (run-yue). For example, the leap month that follows immediately the 6-th lunar month is called the 6-th leap month. A (leap) month is either a short or long one, which has 29 or 30 days respectively. There are 10 gan's and 12 zhi's. The ganzhi labeling of the year, month, day and hour of a date is a member of the Cartesian product GxGxGxG, where G = {1,2,...,60}. For example, "jia-zi" is 1, "yi-chou" is 2, and so on. The ganzhi of the j-th leap month is the same as that of the j-th month. The possible options are b output ganzhi in special "bitmap" characters. h output hanzi or Chinese characters encoded in (highest-bit-set) GB code. i convert a lunar date to solar date. The default is to convert a solar date to a lunar date. l indicate the month is a lunar leap month. This option is meaningful only when the "-i" option is used. COPYRIGHT
Copyright (C) 1988, 1989, 1991, 1992, 2001 Fung F. Lee and Ricky Yeung This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. The last version of this program was released on July 23, 1992 as version 2.1a. This program was first released under the terms of GNU GPL on October 28, 2001 as version 2.2. Both versions are identical except for the license text. AUTHORS
Fung F. Lee and Ricky Yeung ACKNOWLEDGEMENT
The special "bitmap" file "lunar.bitmap" was contributed by Weimin Liu. Special thanks to Hwei Chen Ti who extended the tables from 2001 to 2049. BUGS
Bug reports and comments should be sent to lee@umunhum.stanford.edu. DISCLAIMER
This software has no connection with our employers. 28 October 2001 lunar(1)
All times are GMT -4. The time now is 10:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy