Time using Time::Local


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time using Time::Local
# 1  
Old 02-02-2006
Time using Time::Local

Can someone tell me how to get the current date and time in the follwoing format, using Time::Local?

MM/DD/YYYY HH:MI:SS AM/PM
# 2  
Old 02-02-2006
If this is Perl, why need Time::Local? Time::Local is for getting a Unix timestamp from given time fields that can be used for further processing. It won't give you the date formatting.

A primitive, clumsy way but certainly works:

Quote:
[bernardchan@bernardchan ~]$ perl -e '@t = localtime time; printf("%02d/%02d/%4d %02d:%02d:%02d %s", $t[4]+1, $t[3], $t[5]+1900, $t[2]-($t[2]>12?12:0), $t[1], $t[0], ($t[2]>=12?"PM":"AM"))'
02/03/2006 09:21:35 AM
Or install Time::Format. It has a flexible way of formatting date and time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

AIX errpt : ( E7A89C7D Local adapter disabled after unstable singleton for long time )

Medel : 9117-MMC OS: AIX 6.1 Patch level : 6100-07-04-1216 Hacmp version : HACMP v 6.1.0.8 Oracle : 11.2.0.3 RAC Node : 2 node Dear, my one node server has been restarted early this morning, So, i tried to start HA and Oracle database. after that, the follow error appears at the node... (1 Reply)
Discussion started by: tomato00
1 Replies

2. Shell Programming and Scripting

Local time to GMT time

Gents, Please can help with this. the column in red is the local time the column in blue is the GPStime 4153152529951 2/12/17 12:00:04.980 951 2960 41531.0 52529.0 1170882022980002 4108153261942 2/12/17 12:00:07.944 942 2959 41081.0 53261.0 1170882025944002 41511523611660... (7 Replies)
Discussion started by: jiam912
7 Replies

3. Shell Programming and Scripting

GMT to local Time conversion

How can I convert the following date format: New Log Date = 2016-12-30 23:50:33 GMT from GMT time to local time? Thanks (13 Replies)
Discussion started by: mrn6430
13 Replies

4. Shell Programming and Scripting

Unable to create logfile with local time stamp using perl

Hello All, Morning, I am facing problem with my code while creating a log with name as current time stamp using perl. Here is the code. #!/usr/bin/perl my $time=localtime; my ($day,$month,$date,$tm,$year)=split(/ /,$time); my $stamp=$year."_".$month."_".$date; my... (4 Replies)
Discussion started by: krsnadasa
4 Replies

5. UNIX for Dummies Questions & Answers

UTC time and Local time

Hi, A few days ago I changed my CentOS box's timezone to -07:00. Now the date commands output look like this (run almost simultaneously, less than 1 second delay).. # date Mon Sep 5 20:23:40 PDT 2011 # date -u Tue Sep 6 03:24:05 UTC 2011 The hours difference seems correct, but why is... (2 Replies)
Discussion started by: forte712
2 Replies

6. Solaris

Enabling time service in local zones

Hi, Is it possible to enable the time service in local zones? E.g. erahmanz1% svcs -a | grep -i time STATE STIME FMRI disabled Sep_10 svc:/network/daytime:dgram disabled Sep_10 svc:/network/daytime:stream disabled Sep_10 svc:/network/time:dgram... (2 Replies)
Discussion started by: ERahman
2 Replies

7. AIX

Convert UTC time to local time ?

Hello, Using AIX6.1 box. I have UTC time value and need to convert it to local time value - I mean time zone and DST should be taken into consideration. I hope it could be done using shell environment - I don't want to write a program. thanks Vilius ---------- Post updated at 02:30 PM... (2 Replies)
Discussion started by: vilius
2 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. Shell Programming and Scripting

save weather radar to local time-named file every 15 minutes

I think I can do this myself now, but I am always amazed by how people can do things cleaner and simpler than I end up doing... Using cron, I want to save the image found at: http://radar.weather.gov/ridge/Conus/RadarImg/centgrtlakes.gif every 15 minutes to a local file , such as ... (1 Reply)
Discussion started by: brucewestfall
1 Replies

10. Shell Programming and Scripting

conversion from EPOCH timestamp to local time zone

hello gurus, i want a perl/shell script which once invoked should convert a set of EPOCH timestamps to local time ( IST..i want) . how does it work ,i have an idea on that..but writing a perl/shell script for it is not possible for me...so i need help for the same. my exact requirement is... (2 Replies)
Discussion started by: abhijeetkul
2 Replies
Login or Register to Ask a Question