1

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.

Kirubakaran
  • 378
  • 4
  • 20
  • 1
    Please edit your question and show us what you have tried. The API is only going to return it in the timezone it has so your going to have to covert it yourself once you get it. – Linda Lawton - DaImTo Jun 17 '19 at 07:02
  • Yes, it is right. How we can convert this into IST? can we have any tool for this in Linux? – Kirubakaran Jun 17 '19 at 09:05
  • Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – Linda Lawton - DaImTo Jun 18 '19 at 06:31

2 Answers2

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
Jescanellas
  • 2,555
  • 2
  • 9
  • 20
  • Hi Jescanellas, This is what I expected and it works fine in bash. Is there any way to handle this time conversion in C language? – Kirubakaran Jun 17 '19 at 12:12
  • Sadly I'm not into C, but this examples might be useful to you: https://stackoverflow.com/questions/13804095/get-the-time-zone-gmt-offset-in-c and: https://stackoverflow.com/questions/48771851/im-trying-to-build-an-rfc3339-timestamp-in-c-how-do-i-get-the-timezone-offset – Jescanellas Jun 18 '19 at 09:26
  • Is there any way to handle this time conversion in Python instead of C? I googled some links on this but bit tricky. So, I have asked here itself. – Kirubakaran Jul 19 '19 at 20:56
0

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.

Titulum
  • 9,928
  • 11
  • 41
  • 79