繁体   English   中英

在 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

我将 xml 文件导入到 Excel 中,日期格式为 yyyy-MM-ddTHH:mm:ssZ ,如何将格式更改为 yyyyy-mm-dd HH:MM:ss 或 Unix 格式?

谢谢!

去你的excel做这个

搜索您的格式类型并完成

更新 1:好的,试试看

 Sub ChangeDateFormat()

Application.ScreenUpdating = False

Dim CurrentCell As Range
Dim LastRow As Long
Dim RegEx As Object
Set RegEx = CreateObject("vbscript.regexp")
RegEx.Global = True

LastRow = Range("A" & Rows.Count).End(xlUp).Row 'Get The Last Row in Column Change A as Needed

For Each CurrentCell In Range("A1:A" & LastRow) ' Loop through all cells. Change Column as needed

   If InStr(CurrentCell.Value, "/") <> 0 Then 'To make sure only convert non converted ones

     RegEx.Pattern = "(\d{4})/(\d{2})/(\d{4}) (\d{2}):(\d{2}):(\d{2})" ' Seperate all parts of imported Data into groups
       CurrentCell.Value = RegEx.Replace(CurrentCell.Value, "$3.$2.$1 $4:$5") ' Change order of groups and place into cell.

   End If

Next

Application.ScreenUpdating = True

End Sub

根据需要更改代码

更新 2:试试看

format(now(), "yyyy-MM-dd hh:mm:ss")

字符串 "yyyy-MM-ddTHH:mm:ssZ" 可以使用以下函数更改为日期 оr 将 "T" 替换为 " " 并将 "Z" 替换为 ""

Function StrToDate(str As String) As Date
    StrToDate = CDate(Replace(Replace(str, "T", " "), "Z", ""))
End Function

暂无
暂无

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

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