如何将RFC 3339日期时间转换为IST? [英] How to convert RFC 3339 date-time to IST?
问题描述
我正在使用Google云端硬盘剩余API列出我的Google云端硬盘文件。我正在读取驱动器中文件的元数据以下的内容。这样,我就获得了RFC 3339格式的创建时间。
您能帮我将Google Drive Rest API返回的时间转换为IST吗?在Linux平台上有什么办法?
{
files:[
{
id: 1y_GB6OCBENf_gDMAzAHdN,
名称: 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。
您可以这样操作: #!/ bin / bash
your_date = 2019-06-17T02:08:50.959Z
#从日期
formatZ中删除Z = $ {your_date // Z}
#将T替换为
formatT = $(echo $ formatZ | tr T)
#使用命令日期转换我们格式化的日期
newdate = $(TZ = IST日期-d $ formatT UTC-5:30)
echo $ newdate
I was working with Google drive rest APIs to list my Google drive files. I was fetching below metadata of the file in my drive. In that, I am getting the "Created Time" in RFC 3339 format. Can you help me to convert the time returned by the Google drive rest APIs to IST? Is there any way to do this in Linux platform?
{
"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"
}
]
}
Note: I was using curl tool to access Google drive rest APIs from my Linux server.
I understand that you want to get the creation date of your files, convert it to IST and use it in your code, but correct me if I’m wrong. You could do it this way:
#!/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
这篇关于如何将RFC 3339日期时间转换为IST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!