简体   繁体   English

如何将 2020-01-06T17:11:58.643Z 之类的 javascript 日期转换为 excel 中的日期时间?

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

相关问题 如何转换“2021-06-01T11:17:00-07:00”之类的日期以获取 javascript 中特定位置(新德里)的日期时间? - How to convert date like '2021-06-01T11:17:00-07:00' to get date time for particular location (New Delhi) in javascript? 将这样的日期格式转换为 2020 年 4 月 20 日星期五 00:00:00 GMT+0530(印度标准时间)到 Javascript 中的 2020-04-20T00:00:00.000Z - convert Date format like this Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time) to 2020-04-20T00:00:00.000Z in Javascript Javascript + Jquery + Sharepoint 日期格式错误 2020-10-01T19:01:00.0000000Z;2020-10-01T04:00:00.0000000Z - Javascript + Jquery + Sharepoint date format error 2020-10-01T19:01:00.0000000Z;2020-10-01T04:00:00.0000000Z 如何使用 JavaScript 将我的日期“2020 年 1 月 1 日星期三 00:00:00 GMT+0530(印度标准时间)”转换为 2020 年 1 月 1 日? - How can I convert my date “Wed Jan 01 2020 00:00:00 GMT+0530 (India Standard Time) ” to JAN 01,2020 using JavaScript? 如何使用 JavaScript 生成 2015-12-23T15:17:52.000Z 格式的日期/时间 - How to Generate Date/Time in 2015-12-23T15:17:52.000Z Format with JavaScript 如何检查2017-03-29T06:45:00.000Z是否等于现在的日期和时间? - How to check if 2017-03-29T06:45:00.000Z is equal to the date and time now? 如何在 js 中获取格式为 2020-01-16 07:29:43.657519000 Z 的日期? - How do I get a date with format 2020-01-16 07:29:43.657519000 Z in js? JavaScript将DateTime:“ 2017:10:01 19:06:57”字符串转换为ISO日期字符串 - JavaScript convert DateTime:“2017:10:01 19:06:57” string to ISO date string 如何将此日期格式 2021-03-30T06:14:00.000Z 转换为 2021-03-30T06:14:00+00:00 Javascript 中的此日期格式 - How can I convert this date format 2021-03-30T06:14:00.000Z to 2021-03-30T06:14:00+00:00 this date format in Javascript Javascript:如何获取 2020-05-15T05:00:00Z 格式的日期字符串? - Javascript: How to get 2020-05-15T05:00:00Z format date string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM