没有日期时间模块的Perl转换日期时区 [英] Perl convert date timezone without datetime module
本文介绍了没有日期时间模块的Perl转换日期时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个日期,格式为:2013年5月26日06:08:00
上述日期的时区为格林尼治标准时间-7
I have a date in the format: 05/26/2013 06:08:00
The timezone of above date is GMT -7
我如何将以上内容更改为GMT日期和时间以及格式: 2013年5月26日格林尼治标准时间13:08:00
how can i change the above to GMT date and time and in format: 26 May 2013 13:08:00 GMT
注意:我无法安装任何perl模块.我知道我可以通过DateTime轻松完成此操作,但无法安装.
Note: I cannot install any perl module. I know that i can do this easily via DateTime but i cannot install it.
谢谢.
推荐答案
您可以使用时间::部分,该文件应包含在您的Perl安装中.
You can use Time::Piece which should be included with your Perl installation.
use Time::Piece;
my $datetime = '05/26/2013 06:08:00';
$datetime .= '-0700'; # attach the timezone offset
my $dt = Time::Piece->strptime($datetime, '%m/%d/%Y %H:%M:%S %z');
print $dt->strftime('%d %b %Y %H:%M:%S');
这篇关于没有日期时间模块的Perl转换日期时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文