[英]Perl Format yyyy-mm-dd HH:mm:ss to yyyy-mm-dd in Excel
I am trying to write to an Excel
sheet using Excel::Writer:XLSX
. 我正在尝试使用
Excel::Writer:XLSX
写入Excel
表。
I know that it is possible to do date time format using write_date_time( $row, $col, $date_string, $format )
我知道可以使用
write_date_time( $row, $col, $date_string, $format )
进行日期时间格式化
However, $date_string
has to be one of these formats (the T is required) 但是,
$date_string
必须是以下格式之一(必须为T)
yyyy-mm-ddThh:mm:ss.sss # Standard format
yyyy-mm-ddT # No time
Thh:mm:ss.sss # No date
yyyy-mm-ddThh:mm:ss.sssZ # Additional Z (but not time zones)
yyyy-mm-ddThh:mm:ss # No fractional seconds
yyyy-mm-ddThh:mm # No seconds
The problem is the string I have right now is in the format yyyy-mm-dd HH:mm:ss
. 问题是我现在拥有的字符串格式为
yyyy-mm-dd HH:mm:ss
。 Is there a workaround for this? 有没有解决方法?
Just replace the space 只需更换空间
in your timestamps with a
T
with a regular expression. 在您的时间戳记中使用带正则表达式的
T
If the timestamps are consistent, that will work. 如果时间戳是一致的,那将起作用。
write_date_time( $row, $col, $date_string =~ tr/ /T/r, $format );
This transliterates spaces 音译空间
into capital Ts
T
and returns the result instead of changing in-place. 输入大写字母Ts
T
并返回结果,而不是就地更改。
See perlop . 参见perlop 。 The
/r
flag requires at least Perl 5.14. /r
标志至少需要Perl 5.14。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.