得到当前系统的时间[未完稿]

得到当前系统的时间[未完稿]

得到当前系统的时间[未完稿]
###################################
($sec,$min,$hour,$mday,$mon,$year)= localtime(time+(3600*$time_hour));
$mon=$mon+1;
if($mon<10){$mon="0".$mon;}
if($mday<10){$mday="0".$mday;}
if($hour<10){$hour="0".$hour;}
if($min<10){$min="0".$min;}
if($sec<10){$sec="0".$sec;}
$year=$year+1900;
$thistime="$year-$mon-$mday $hour:$min:$sec";
==========================================================
($sec,$min,$hour,$dd,$mon,$yy,$wday,$yday,$isdst)= gmtime($time+$timezone);
$yyyy = $yy+1900;
$mm = $mon+1;
($mm < 10) and ($mm = "0$mm");
($dd < 10) and ($dd = "0$dd");
($hour < 10) and ($hour = "0$hour");
($min < 10) and ($min = "0$min");
$thistime="$year-$mon-$mday $hour:$min:$sec";
########################################
sub format_time--{--.
sub format_time
{
my ($format,$time) = @_;
my @wanday = qw/ Sun. Mon. Tue. Wed. Thu. Fri. Sat. /;
$format ||= '%Y%-%M%-%D% %h%:%m%:%s% %P% %W%';
$time ||= time; #$TIME_OFFSET ? time + 3600 * $TIME_OFFSET : time;
my @lt = localtime($time);
$f{Y} = $lt[5]+1900;
$f{M} = sprintf("%02d",$lt[4]+1);
$f{D} = sprintf("%02d",$lt[3]);
$f{W} = $wanday[$lt[6]];
$f{h} = sprintf("%02d",$lt[2]);
$f{m} = sprintf("%02d",$lt[1]);
$f{s} = sprintf("%02d",$lt[0]);
$f{P} = $lt[2] > 11 ? 'pm' : 'am';
$format =~ s!%(\w)%!$f{$1}!g
if defined $format;
$format;
};




   

to 楼主:
你那两段代码也太差劲了,Perl 代码不是这么写的,BASIC 都不那么写了,
有 sprintf 函数为什么不用?

($sec,$min,$hour,$mday,$mon,$year)= localtime(time+(3600*$time_hour));
$thistime= sprintf( "%4d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec );
这就可以了。




   

use POSIX (qw/strftime/).
use POSIX (qw/strftime/);
my $cur_time = strftime( "%Y-%m-%d %H:%M:%S", localtime() );
[quote]回复给 flw : to 楼主:--你那两段代?....[/quote]
你们两的差别:
2006- 7-17 10:51:43 ---------7前面有空格
2006-07-17 10:51:43
[quote]回复给 flw : to ?
[quote]回复给 flw : to 楼主:--你那两段代?....[/quote]
错误提示:Unrecognized character \xA1 at 1.pl line 2.[CCB]c15[/CCB]




   

[quote]回复给 termitor :.
[quote]回复给 termitor : [quote]回复给 flw : to ?...[/quote]

" $hour"
改成
" $hour" 就可以
[quote]回复给 flw : to ?
[quote]回复给 flw : to 楼主:--你那两段代?....[/quote]

汗...what's "也太差劲了"?当然欢迎优秀的代码,但带"感情"和"个人情绪"的用词还是少用为好,此栏目是为了吸引更多的初学者,不能打击他们的学习积极性...楼主的写法对于初学者更容易搞懂,不一定是坏事


[CCB]6[/CCB]




   

$thistime= sprintf( "%4d.
$thistime= sprintf( "%4d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec );
既然都sprintf你还要$thistime做什么
难道想看看sprintf是不是成功?