Sponsored Content
Full Discussion: PERL localtime Warning
Top Forums Shell Programming and Scripting PERL localtime Warning Post 302412144 by NIMISH AGARWAL on Monday 12th of April 2010 12:52:47 AM
Old 04-12-2010
Question here is the function

Code:
ub Timestamp
{
 my ($time) = (@_);
 my ($sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst) = localtime($time);
if(length($hour) == 1) {
		$hour = "0" . $hour;
	}
	if(length($min) == 1) {
		$min = "0" . $min;
	}
	if(length($sec) == 1) {
		$sec = "0" . $sec;
	}

	# Set to 2 digit month from 01 to 12
	$month += 1;
	if(length($month) == 1) {
  		$month = "0" . $month;
	}
	# Set to 2 digit day
	if(length($mday) == 1) {
		$mday = "0" . $mday;
	}
	# Use four digit year ($year is a value based on # of years since 1900)
	$year += 1900;
	
	$currentTime = "$hour$min";			# Set for checking suspending activity
	
	return("$year-$month-$mday $hour:$min:$sec");
}


Last edited by pludi; 04-12-2010 at 02:25 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl + localtime()

ok here is a perl date question not asked befor. i know i am feeling small for not knowing. BUT!!!! $ENV{TZ}="US/Central"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(); how can i do the addition to year so i can get the current year w/o going $ntime=$year+1900;... (3 Replies)
Discussion started by: Optimus_P
3 Replies

2. UNIX for Advanced & Expert Users

converting localtime to unixtime

hi, how to convert the localtime to unixtime? i have date from the date command in unix i want to convert it into unixtime thnx (2 Replies)
Discussion started by: AshishK
2 Replies

3. HP-UX

sleep & localtime query

Hi, I work on HPUX application and i had a query regarding the sleep & localtime system call in HPUX. Here is the code that we have : const uint32_t WAKE_INTERVAL_SEC(30*60); while (true) { // Find out what time it is time(&currentTime);... (3 Replies)
Discussion started by: nsvora
3 Replies

4. Shell Programming and Scripting

date with perl localtime

Hi Experts, I know how to handle normal date changes in perl. Most of my requirement are full filled with following: $date1 = strftime "%Y%m%d",localtime; $date2 = strftime "%Y%m%d",localtime(time -24 * 60 * 60); $date3 = strftime "%Y%m%d",localtime(time +24 * 60 * 60); $date4 = strftime... (4 Replies)
Discussion started by: mtomar
4 Replies

5. Shell Programming and Scripting

what is the default return type of localtime() in perl?

Hi, I have given like this to get the time of the sub routine. my $start = localtime(); print "\n start time: $start \n"; Output start time: Fri Apr 29 01:01:31 2011 I want to know what is the format of the time. I am not able to follow is is HH:MM:SS or MM:HH:SS os... (2 Replies)
Discussion started by: vanitham
2 Replies

6. Shell Programming and Scripting

Pack and unpack localtime in perl script

Hi I have a code like this: sub WriteEbcdicHeader { my $Htimestamp=localtime();#i need to pack and unpack this my $eheaderline = $Htimestamp; #packing has to be done here #unpacking has to be done after packing print $EOUTFILE return $eheaderline; } sub WriteEbcdicTrailer { ... (5 Replies)
Discussion started by: rbathena
5 Replies

7. Shell Programming and Scripting

Perl help LocalTime in New Format

Hi, I'm new to perl scripting and am trying it out. I have a file written in the following format: myfile-MMDDYY where MM is the number of the Month; DD the Day and YY the last two of the year... (Apologies for dumbing this down; I'm trying to be clear). There is a new file put onto my... (2 Replies)
Discussion started by: Astrocloud
2 Replies

8. Shell Programming and Scripting

How to use a variable in perl localtime()?

Hi all, a=$1 ## b=`echo "86400 * $a"|bc` `perl -e 'use POSIX qw(strftime);$now_string = strftime "%d/%m/%Y", localtime(time-$b); print $now_string,"\n";' > date_file` but im always getting current date; can any one suggest me any the improvement the above works fine if i use some thing... (2 Replies)
Discussion started by: zozoo
2 Replies

9. Programming

TZ, localtime and strftime problem on AIX and Solaris

Hello all, I have the following code that seems to be misbehaving depending on the timezone setting (TZ Environment variable). It gives the correct value when TZ is in POSIX format and the wrong value when in OLSON format. #include <stdio.h> #include <stdlib.h> #include <time.h> #include... (6 Replies)
Discussion started by: biju64
6 Replies

10. AIX

Perl error : perl: warning: Setting locale failed.

This's my problem perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LC_ALL = "en_US.UTF-8", LC__FASTMSG = "true", LC_MESSAGES = "", LC_CTYPE = "en_US.UTF-8", LC_TYPE = "en_US.UTF-8", LANG = "EN_US"... (1 Reply)
Discussion started by: bobochacha29
1 Replies
LOCALTIME(3)								 1							      LOCALTIME(3)

localtime - Get the local time

SYNOPSIS
array localtime ([int $timestamp = time()], [bool $is_associative = false]) DESCRIPTION
The localtime(3) function returns an array identical to that of the structure returned by the C function call. PARAMETERS
o $timestamp - The optional $timestamp parameter is an integer Unix timestamp that defaults to the current local time if a $timestamp is not given. In other words, it defaults to the value of time(3). o $is_associative - If set to FALSE or not supplied then the array is returned as a regular, numerically indexed array. If the argument is set to TRUE then localtime(3) returns an associative array containing all the different elements of the structure returned by the C func- tion call to localtime. The names of the different keys of the associative array are as follows: o "tm_sec" - seconds, 0 to 59 o "tm_min" - minutes, 0 to 59 o "tm_hour" - hours, 0 to 23 o "tm_mday" - day of the month, 1 to 31 o "tm_mon" - month of the year, 0 (Jan) to 11 (Dec) o "tm_year" - years since 1900 o "tm_wday" - day of the week, 0 (Sun) to 6 (Sat) o "tm_yday" - day of the year, 0 to 365 o "tm_isdst" - is daylight savings time in effect? Positive if yes, 0 if not, negative if unknown. ERRORS
/EXCEPTIONS Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the $TZ environment variable. See also date_default_timezone_set(3) CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | Now issues the E_STRICT and E_NOTICE time zone | | | errors. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 localtime(3) example <?php $localtime = localtime(); $localtime_assoc = localtime(time(), true); print_r($localtime); print_r($localtime_assoc); ?> The above example will output something similar to: Array ( [0] => 24 [1] => 3 [2] => 19 [3] => 3 [4] => 3 [5] => 105 [6] => 0 [7] => 92 [8] => 1 ) Array ( [tm_sec] => 24 [tm_min] => 3 [tm_hour] => 19 [tm_mday] => 3 [tm_mon] => 3 [tm_year] => 105 [tm_wday] => 0 [tm_yday] => 92 [tm_isdst] => 1 ) SEE ALSO
getdate(3). PHP Documentation Group LOCALTIME(3)
All times are GMT -4. The time now is 11:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy