简体   繁体   English

Excel - 将以 Z 结尾的 ISO8601 日期转换为适合输入“带时区的时间戳”类型的 Postgres 字段的格式

[英]Excel - convert ISO8601 date ending in Z into format suitable for entry into Postgres field with type 'timestamp with time zone'

I have a CSV file that I'm opening in Excel.我有一个要在 Excel 中打开的 CSV 文件。 It has dates in this format:它具有以下格式的日期:

2019-09-15T00:11:57.4030000Z

I want this:我要这个:

2019-09-15 00:11:57.403+00

I think I may be able to use the "format cells > custom" option in Excel, but what would do I need to specify as the 'type' for the format?我想我可以在 Excel 中使用“格式化单元格 > 自定义”选项,但是我需要指定什么作为格式的“类型”? I tried using this to get most of it, but it doesnt' work:我尝试使用它来获取大部分内容,但它不起作用:

yyyy-mm-dd hh:mm:ss.000

And when I try to apply some of the pre-existing types built into Excel, they don't seem to change the date format - it's as if the original date format isn't being recognised as valid.当我尝试应用 Excel 中内置的一些预先存在的类型时,它们似乎没有更改日期格式 - 就好像原始日期格式未被识别为有效一样。

My OP asks how to do this in Excel, however I found it easier to parse the file with a regex.我的 OP 询问如何在 Excel 中执行此操作,但是我发现使用正则表达式解析文件更容易。 I used the excellent dnGrep tool for this, with the following pattern, that groups the date and time into substitution groups, then uses them in the replacement as $1 and $2 :为此,我使用了出色的dnGrep工具,采用以下模式,将日期和时间分组到替换组中,然后在替换中将它们用作$1$2

search - ([0-9]{4}[-][0-9]{2}[-][0-9]{2})[T]([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})[0-9]{4}Z搜索 - ([0-9]{4}[-][0-9]{2}[-][0-9]{2})[T]([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})[0-9]{4}Z

replace - $1 $2+00更换 - $1 $2+00

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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