Perl中今天的日期为MM / DD / YYYY格式 [英] Today's Date in Perl in MM/DD/YYYY format

查看:82
本文介绍了Perl中今天的日期为MM / DD / YYYY格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工作中正在开发Perl程序,并坚持(我认为是)一个微不足道的问题。我只需要以'06 / 13/2012'格式建立一个字符串(总是10个字符,所以0的数字小于10)。



到目前为止:

 使用Time :: localtime; 
$ tm = localtime;
我的($ day,$ month,$ year)=($ tm-> mday,$ tm->月,$ tm->年);


解决方案

你可以快速做,只使用一个< href =http://p3rl.org/POSIX =noreferrer> POSIX 功能。如果您有一系列具有日期的任务,请参阅 DateTime 模块。

 使用POSIX qw(strftime); 

我的$ date = strftime%m /%d /%Y,localtime;
打印$ date;


I'm working on a Perl program at work and stuck on (what I think is) a trivial problem. I simply need to build a string in the format '06/13/2012' (always 10 characters, so 0's for numbers less than 10).

Here's what I have so far:

use Time::localtime;
$tm=localtime;
my ($day,$month,$year)=($tm->mday,$tm->month,$tm->year);

解决方案

You can do it fast, only using one POSIX function. If you have bunch of tasks with dates, see the module DateTime.

use POSIX qw(strftime);

my $date = strftime "%m/%d/%Y", localtime;
print $date;

这篇关于Perl中今天的日期为MM / DD / YYYY格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆