问题
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.
回答1:
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
回答2:
You can use the date
command for parsing the ISO 8601/RFC 3339 timestamp, and then use the date
command again for converting it to another timezone.
来源:https://stackoverflow.com/questions/56624057/how-to-convert-rfc-3339-date-time-to-ist