Can anyone help me to print UNIX epoch time to days,hours,min,sec ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can anyone help me to print UNIX epoch time to days,hours,min,sec ?
# 1  
Old 10-04-2015
Can anyone help me to print UNIX epoch time to days,hours,min,sec ?

I have unix epoch time 1441678454803, Can you please help me to print this time in below format ?

DAY,HOUR,MIN,SEC

Appreciate your help!!!

Thanks,
Prince
# 2  
Old 10-04-2015
Code:
#!/usr/bin/perl

# convert_epoch.pl

use strict;
use warnings;

my $epoch = shift or die;
my ($sec, $min, $hour, $day) = (localtime($epoch))[0,1,2,3];
print "$day,$hour,$min,$sec\n";

Run as perl convert_epoch.pl 1441678454803
This User Gave Thanks to Aia For This Post:
# 3  
Old 10-04-2015
As a note - with Linux (GNU date) try:
Code:
 date --date='@1441678454803' +'%a %H %m %S'

Bad number? It is for the year 47654
Plus the number you gave will not work as a valid UNIX epoch second on a lot of older systems because it is for the year far in the future -- %Y prints the full year 4 or more digits. I ran this on a 64 bit OS so it would correctly output:

Code:
 date --date='@1441678454803' +'%a %H %m %S %Y'
Sun 22 12 43 47654

So I would question this number as a valid date
This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 10-05-2015
Do you know any commands in UNIX without perl script? For example if its 25 hours, then our result should be.

1day,1hour,0min,0sec.

Appreciate your help!
Thanks

---------- Post updated at 09:11 AM ---------- Previous update was at 09:04 AM ----------

Can you calculate with 1443929685, For example if its 25 hours, then our result should be.

1day,1hour,0min,0sec.

Appreciate your help!
Thanks
# 5  
Old 10-05-2015
Quote:
Originally Posted by prince1987
Do you know any commands in UNIX without perl script? For example if its 25 hours, then our result should be.

1day,1hour,0min,0sec.

Appreciate your help!
Thanks

---------- Post updated at 09:11 AM ---------- Previous update was at 09:04 AM ----------

Can you calculate with 1443929685, For example if its 25 hours, then our result should be.

1day,1hour,0min,0sec.

Appreciate your help!
Thanks
It appears you are confusing what epoch time is. That 1443929685 is the representation in seconds of a specific time; in this case Sat Oct 3 21:34:45 2015 in my timezone
There is not way of getting 1day,1hour,0min,0sec unless you are computing the difference against another time.
Please, mention what shell you are using if you do not want to use Perl.
# 6  
Old 10-05-2015
Hello,

Am using kernel shell. Aww computing help me.

Thanks,
# 7  
Old 10-05-2015
You probably mean the korn shell. If you have the korn shell 93 on your system, you can use
Code:
$ printf "%(%Y-%m-%d %T)T\n" '#1443929685'
2015-10-04 05:34:45

This requires the printf builtin function, which is activated by default in ksh93, not /usr/bin/printf. By changing the format string in the printf statement you can easily change the output format.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to run cron entry every 5 min during office hours only?

Hi I need to setuop a cron entry to run every 5 min, only in office hours (between 8:00AM to 18:00PM, I did the following: 0,5,10,15,20,25,30,35,40,45,50,55 8,9,10,11,12,13,14,15,16,17,18 * * * /home/xxx/zzz.ksh But somehow does not work. Could it be wrong? (8 Replies)
Discussion started by: fretagi
8 Replies

2. Shell Programming and Scripting

Convert Second Column Date Into EPOCH Time And Print Complete Row

Hello Team, I am stuck in getting the required output in the following case. Please help. My input file is aa|08/01/2016 bb|08/15/2016 I wish to convert the file into aa|epoch time bb|epoch time I am using following code: (3 Replies)
Discussion started by: angshuman
3 Replies

3. Shell Programming and Scripting

Get the no of hours between days

Hi, i have a date 1- 2013101511 date2 -2013101812 need toget the no of hours between them,can any one tellme the logic. (6 Replies)
Discussion started by: sandeep karna
6 Replies

4. Shell Programming and Scripting

Adding Seconds to UNIX/Epoch-Time

Hello All, I have a Perl script I'm writing where I ask the user to enter a "start time" for something. The "$start_time" will be in the format of: # The Time CLI Option Can be in the format of: --start-time="1day" --start-time="2hours" --start-time="45min" ... (1 Reply)
Discussion started by: mrm5102
1 Replies

5. 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

6. Shell Programming and Scripting

Capture running process or 2 hours with an interval of 10 sec

Hi, Can any one help me on this. How to capture the running process for two hours with an interval of 10 sec. Thanks in andvance (1 Reply)
Discussion started by: sarathkumar
1 Replies

7. UNIX for Dummies Questions & Answers

Capture running process for 2 hours with an interval of 10 sec

Hi, Can any one help me on this. How to capture the running process for two hours with an interval of 10 sec. Thanks in andvance Double post, continued here, thread closed (0 Replies)
Discussion started by: sarathkumar
0 Replies

8. Shell Programming and Scripting

How to calculate unix epoch time with DC(Calculator)

Hi All, In our code we are using below code to calculate the UNIX Epoch Time from the time stamp present in the file. Can any one explain how the DC operates in below command and how we calculate the UNIX EPOCH time from this. Date incide the file is 20:26:51 Output we get is 1289943554... (3 Replies)
Discussion started by: mithunpatel
3 Replies

9. 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

10. Shell Programming and Scripting

Add data in days:hours:min:sec format

I want to add these no. these are in the format of days:hours:minutes:sec I want result in this format only 0:00:04:59 0:00:00:12 0:00:00:28 0:00:00:03 0:01:29:35 0:00:00:19 0:01:05:21 Is any body ca help me????? To get This.. Thanks Nishant (1 Reply)
Discussion started by: krishna_sicsr
1 Replies
Login or Register to Ask a Question