Converting Epoch time


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Converting Epoch time
# 1  
Old 01-02-2014
Converting Epoch time

I have a Raspberry Pi that logs some temperatures using Onewire. Data is collected with RRDTool.
The command
Code:
sudo rrdtool fetch ute_temp.rrd AVERAGE -s -1h > ./test.log

and then
Code:
cat test.log

gives the result
Code:
1388608500: 2.3579639836e+00

.

How do I write a script that converts the Epoch time stamps to normal readable time and printing the result on a new file?

I plan to use the logfile in Excel to analyze my data. (Have not found any tools in Excel to convert Epoch time to human time.

Thanks for any help.

/Nils
# 2  
Old 01-02-2014
Epoch time conversion should be handled on the system where you are recording time. You can use awk (gawk) or perl. Check your level of awk on your system for mktime() systime(),strftime(). See

Code:
http://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html

Code:
http://stackoverflow.com/questions/95492/how-do-i-convert-a-date-time-to-epoch-time-aka-unix-time-seconds-since-1970

This User Gave Thanks to blackrageous For This Post:
# 3  
Old 01-03-2014
I was given this a while back. It relys on Perl, but it works for me on HP-UX and AIX:-
Code:
$ cat realtime
perl -e 'print scalar localtime $ARGV[0],"\n" ' $1

Code:
$ ./realtime 1234567890
Fri Feb 13 23:31:30 2009


Robin
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 01-03-2014
With ksh93 you can write
Code:
printf "%(%Y-%m-%d %T)T\n" '#'1388745871

Make sure, that you use the printf-builtin, which should be the default.
These 2 Users Gave Thanks to hergp For This Post:
# 5  
Old 01-03-2014
I added a function to my .profile and use it all the time:
HTML Code:
function lt {
perl -we "print scalar localtime $1"
echo
}
This User Gave Thanks to port43 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: time intervals based on epoch time

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

2. Shell Programming and Scripting

Converting a random epoch time into a readable format

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)
Discussion started by: sprocket
9 Replies

3. Shell Programming and Scripting

Converting real time to epoch time

# 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

4. Shell Programming and Scripting

converting epoch time to ddmmyy format

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)
Discussion started by: aliyesami
5 Replies

5. Programming

Converting a user inputted date to epoch time

Hi all , I need to know how to convert a time stamp entered by the user to be converted to GMT/UTC(epoch time) using mktime() and gmtime() for exapample the input will be put in the form ptm.tm_sec = 0; ptm.tm_min = 59; ptm.tm_hour = 11; ptm.tm_mday = 20;... (2 Replies)
Discussion started by: ada
2 Replies

6. Shell Programming and Scripting

converting epoch time

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)
Discussion started by: hernand
4 Replies

7. Shell Programming and Scripting

Shell script to convert epoch time to real time

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. Shell Programming and Scripting

epoch time

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

9. Shell Programming and Scripting

how to convert date time to epoch time in solaris

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

10. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

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
Login or Register to Ask a Question