1

我正在使用 Google Drive Rest API 来列出我的 Google Drive 文件。我正在获取驱动器中文件的元数据下方。在那里,我得到了 RFC 3339 格式的“创建时间”。您能帮我将 Google Drive Rest API 返回的时间转换为 IST 吗?在 Linux 平台上有没有办法做到这一点?

{
 "files": [
  {
   "id": "1y_GB6OCBENf_gDMAzAHdN",
   "name": "testfile.jpg",
   "webViewLink": "https://drive.google.com/file/d/1y_GB6OCBENf_gDMAzAHdN/view?usp=drivesdk",
   "createdTime": "2019-06-17T02:08:50.959Z"
   }
  ]
}

注意:我使用 curl 工具从我的 Linux 服务器访问 Google drive rest API。

4

2 回答 2

1

我了解您想要获取文件的创建日期,将其转换为 IST 并在您的代码中使用它,但如果我错了,请纠正我。你可以这样做:

#!/bin/bash

your_date="2019-06-17T02:08:50.959Z"

#Remove the Z from the date
formatZ="${your_date//Z}"

#Replace the T with a space
formatT=$(echo $formatZ | tr T " ") 

#Use the command date to convert the date we formatted
newdate=$(TZ=IST date -d "$formatT UTC-5:30")

echo $newdate
于 2019-06-17T10:38:26.990 回答
0

您可以使用该date命令解析ISO 8601/ RFC 3339timestamp,然后date再次使用该命令将其转换为另一个时区

于 2019-06-17T10:41:38.483 回答