简体   繁体   English

Perl在Excel中将yyyy-mm-dd HH:mm:ss转换为yyyy-mm-dd

[英]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.

相关问题 excel 中的列格式,yyyy-mm-dd hh:mm:ss - Column format in excel, yyyy-mm-dd hh:mm:ss Excel 默认日期时间格式 yyyy-mm-dd hh:mm:ss 与 yyyy-mm-dd hh:mm - Excel default date time format yyyy-mm-dd hh:mm:ss versus yyyy-mm-dd hh:mm 在 Excel 中将 yyyy-MM-ddTHH:mm:ssZ 日期转换为 yyyy-MM-dd HH:MM:ss - Convert yyyy-MM-ddTHH:mm:ssZ date to yyyy-MM-dd HH:MM:ss in Excel 如何使用openpyxl在Excel中使用'yyyy-mm-dd hh:mm:ss'形式的日期时间对象格式化单元格 - How to format cell with datetime object of the form 'yyyy-mm-dd hh:mm:ss' in Excel using openpyxl Excel宏:如何获取“ yyyy-MM-dd hh:mm:ss”格式的时间戳? - Excel Macro : How can I get the timestamp in “yyyy-MM-dd hh:mm:ss” format? 如何在MySQL中导入Excel存储的数据并保持日期格式为yyyy-mm-dd hh:mm:ss - How to import excel stored data in MySQL and keep date format as yyyy-mm-dd hh:mm:ss 在EXCEL中将日期时间(yyyy-mm-dd hh:mm:ss)格式转换为秒 - Converting Date-Time (yyyy-mm-dd hh:mm:ss) format to seconds in EXCEL Excel 从 yyyy-MM-dd'T'HH:mm:ss 转换为 MM - Excel convert from yyyy-MM-dd'T'HH:mm:ss to MM 将整列数据格式从 yyyy-mm-dd hh:mm 更改为 dd/mm/yyyy VBA - Change whole column data format from yyyy-mm-dd hh:mm to dd/mm/yyyy VBA Excel日期公式将文本转换为YYYY-MM-DD HH:MM:SS - Excel date formula to convert text to YYYY-MM-DD HH:MM:SS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM