[英]How to convert javascript date like 2020-01-06T17:11:58.643Z to date time in excel?
I have a javascript dates in an excel table, it looks like this: 2020-01-06T17:11:58.643Z
我在 excel 表中有一个 javascript 日期,它看起来像这样:
2020-01-06T17:11:58.643Z
I want to convert it [using Excel only] to a readable date and time format, ie something like this: 2020-01-06 18:11:58
.我想将它 [仅使用 Excel] 转换为可读的日期和时间格式,即:
2020-01-06 18:11:58
。 Preferably it should be given for a specific Timezone [CET], ie one needs to add one hour.最好是针对特定时区 [CET] 给出,即需要增加一小时。
Are there default Excel functions for that?是否有默认的 Excel 函数? All I can find are functions for converting between different date formats, which are used in different countries.
我能找到的只是用于在不同国家/地区使用的不同日期格式之间进行转换的函数。
As far as a native formula to convert from your javascript notation I don't believe there is one, but here's an inelegant, brute force method with formulas that gets the job done:至于从你的 javascript 符号转换的原生公式,我不相信有一个,但这里有一个不雅的、蛮力的方法,它的公式可以完成工作:
=(DATEVALUE(LEFT(A1,10)) + TIMEVALUE(MID(A1,12,8)) + 1/24)
For those finding this question through a search, Excel stores dates and times as numbers.对于通过搜索发现此问题的人,Excel 将日期和时间存储为数字。 The date is a serial integer representing the number of days since 31 Dec 1899 (1 Jan 1900 is the value "1").
日期是一个序列整数,表示自 1899 年 12 月 31 日以来的天数(1900 年 1 月 1 日是值“1”)。 Time is a decimal from 0.0-0.99999..., where zero is midnight and .99999 being just before midnight the folliwing night.
时间是 0.0-0.99999... 之间的小数,其中零是午夜,0.99999 是紧接在接下来的夜晚午夜之前。 You can join the two together DDDDD.TTTTT.
您可以将两者结合在一起 DDDDD.TTTTT。 For example, I wrote this at 43841.14.
例如,我在 43841.14 写了这个。
To walk through the formula I wrote above, The DATEVALUE()
formula converts a date from text to Excel's numeric date.为了遍历我上面写的公式,
DATEVALUE()
公式将日期从文本转换为 Excel 的数字日期。 The LEFT()
formula provides the 10 left-most characters. LEFT()
公式提供最左边的 10 个字符。 The TIMEVALUE()
formula creates a decimal value for time. TIMEVALUE()
公式为时间创建一个十进制值。 The MID()
formula takes 8 characters starting from the 12th. MID()
公式从第 12 位开始取 8 个字符。 I then add the two together to make one single value holding a date and time together.然后我将两者相加,形成一个包含日期和时间的单一值。 One hour can be represented as one twenty-fourth of one day hence the 1/24 above.
一小时可以表示为一天的二十分之一,因此是上面的 1/24。
This assumes your input is always formatted the same and you are always adding one hour.这假设您的输入格式始终相同,并且您总是添加一小时。 You can use a custom cell format of
yyyy-mm-dd hh:mm:ss
to give the output you request.您可以使用
yyyy-mm-dd hh:mm:ss
的自定义单元格格yyyy-mm-dd hh:mm:ss
来提供您请求的输出。
(Comment converted to answer since nobody else provided any improvements.) (评论转换为答案,因为没有其他人提供任何改进。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.