unixtime to formatted date time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unixtime to formatted date time
# 1  
Old 11-23-2010
unixtime to formatted date time

Hi,

I need to take the unix time and format it to a date/time string like this

yyyymmdd,hhmmss

I'm wrting in shell but have tried calling perl, but all the perl options I found on here puts output to Thu Jan 1 00:00:00 1970 format.

Any help?

Cheers
Neil
# 2  
Old 11-23-2010
Code:
date '+%Y%m%d,%H%M%S'

Code:
# date '+%Y%m%d,%H%M%S'
20101123,175038
# date '+%Y.%m.%d-%H:%M:%S'
2010.11.23-17:50:42
# a=`date '+%Y%m%d,%H%M%S'`                <------ or  a=$(date '+%Y%m%d,%H%M%S')
# echo $a
20101123,175117
#

# 3  
Old 11-23-2010
Sorry,

I think I should have been a little unclear.

I need to take a unixtime and make the conversion output different to standard

example output from perl gives this
Code:
perl -le 'print scalar gmtime(1285659552)'
Tue Sep 28 07:39:12 2010

But I need to format the output so its yyyymmdd,hhmmss (20100928,073912).


Cheers,
Neil

Last edited by Scott; 11-23-2010 at 01:25 PM.. Reason: Code tags
# 4  
Old 11-23-2010
If you have gnudate this will work:

Code:
$ date --date @1285659552 '+%Y%m%d,%H%M%S'
20100928,173912

In perl:

Code:
use POSIX qw(strftime);
print strftime("%Y%m%d,%H%M%S", gmtime(1285659552));


Last edited by Chubler_XL; 11-23-2010 at 05:36 PM..
This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 11-24-2010
That is great...perl option works fine.

The date through an error as it didn't recognise the --date option.


Thanks.
Neil
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

2. Shell Programming and Scripting

awk help reformatting badly formatted time field

I need help reformatting an input file with spaces in the time field (4th field). I want the field to look like “hh:mm” with appropriate embedded zeros, but instead it has “h :m “ if the hour and/or minute are single character. I'm pretty new to scripting and this is beyond me. Any help would... (4 Replies)
Discussion started by: lisep
4 Replies

3. Shell Programming and Scripting

Adding time to date time in UNIX shell scipting

I needed some help in adding a duration (in seconds) to a start time (in hhmmss format) and a start date (in mmddyy format) in order to get an end date and end time. The concept of a leap year is also to be considered while incrementing the day. The code/ function that I have formed so far is as... (3 Replies)
Discussion started by: codehelp04
3 Replies

4. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

5. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

6. Shell Programming and Scripting

Get Formatted Date from Unix Epoch

Could someone please explain how to get a formatted date from the unix epoch (the number of seconds since Jan 1, 1970) For example., If the input is 1297969816, then the output should be 2011-02-17 in YYYY-MM-DD formatted manner. I am using AIX sh shell. Tried date -d and date --date, these... (4 Replies)
Discussion started by: Jesinth Nirmal
4 Replies

7. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

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

9. UNIX for Advanced & Expert Users

find formatted filename with date time

Hi, I operate and use HF radars along the California coast for ocean surface currents. The devices use Mac OS as the control and logging software. The software generates thousands of files a week and while I've used PERL in the past to solve the problems of finding files I come to realize some... (6 Replies)
Discussion started by: dpath2o
6 Replies

10. Shell Programming and Scripting

Convert DATE string to a formatted text

Hi guys, i need your help. I need to convert a date like this one 20071003071023 , to a formated date like 20071003 07:10:23 . Could this be possible ? Regards, Osramos (6 Replies)
Discussion started by: osramos
6 Replies
Login or Register to Ask a Question