0

I am using the below code to convert INPUT(IST-Asia/Kolkata) time to UTC, it worked fine locally but didn't work on AWS batch. I am using pytz module.

def get_utc_time():
    fmt = "%Y-%m-%d %H:%M:%S"
    now_local = "2020-02-13"
    local_date = datetime.strptime(now_local, '%Y-%m-%d')
    change_time = local_date.astimezone(timezone('UTC'))
    utc_date_time =  change_time.strftime(fmt)
    print(utc_date_time)

get_utc_time()

OUTPUT locally on IDE = 2020-02-12 18:30:00
OUTPUT on AWS Batch =  2020-02-13 00:00:00

Expected OUTPUT on aws batch= 2020-02-12 18:30:00


r_narayan
  • 7
  • 5
  • Converting a date (`2020-02-13`) to a different timezone does not make any sense. Plus, your computer is probably running on a different timezone than UTC. Could you possibly tell us what you are _actually_ wanting to accomplish in your code? For example, where will you be getting your input timestamp (preferably with a time) and what are you wanting to convert it into for your users? – John Rotenstein Feb 13 '20 at 04:42
  • suppose I need to fetch the data for (2020-02-13 00:00:00 IST) - so I need to convert it into (Asia/Kolkata) - i.e in UTC(2020-02-12 18:30:00) – r_narayan Feb 13 '20 at 04:57
  • Simply I wanted if the date is - (2020-02-13) then it converts according to (Asia/Kolkata) - (2020-02-13) i.e - 2020-02-12 18:30:00, without adding or hard coding – r_narayan Feb 13 '20 at 05:07

0 Answers0