简体   繁体   中英

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 .

I know that it is possible to do date time format using write_date_time( $row, $col, $date_string, $format )

However, $date_string has to be one of these formats (the T is required)

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 . Is there a workaround for this?

Just replace the space in your timestamps with a T with a regular expression. 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.

See perlop . The /r flag requires at least Perl 5.14.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM