How to change a unix datetime into a different timezone unix datetime
NickName:Sai Krishnadas Ask DateTime:2022-05-19T17:24:55

How to change a unix datetime into a different timezone unix datetime

I get datetime state like: "2022-05-18T18:30:00.000Z" - a moment datetime, then converts it to unix. But I do convert it in my local timezone, How do I change the timezone of the unix datetime and return in same unix format.

Timezone I get - Asia/Singapore

Code:

this.state.startTimeDate.unix() //This is how I convert it to unix format

How to change this unix to a different timezone ?

Copyright Notice:Content Author:「Sai Krishnadas」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72301960/how-to-change-a-unix-datetime-into-a-different-timezone-unix-datetime

Answers
awesome webber 2022-05-20T00:34:06

You could try converting the date to the client timezone before converting back to unix using moment like this ...\nmoment\n .unix(1399335987)\n .tz('MST')\n .format('YYYY-MM-DDTHH:mm:ssZ');\n\nAnd you get\n"2022-05-20T17:01:27-07:00"\n\nBefore converting back to unix again.\nHope this helps",


More about “How to change a unix datetime into a different timezone unix datetime” related questions

How to change a unix datetime into a different timezone unix datetime

I get datetime state like: "2022-05-18T18:30:00.000Z" - a moment datetime, then converts it to unix. But I do convert it in my local timezone, How do I change the timezone of the unix dat...

Show Detail

Parsing DateTime to Unix with Timezone Offset

I have this method that takes in a string such as 2014-03-10T08:00:00 and converts it to a unix number like this: 1394456400 Below is said method: public string convertToUnix(string dateString) {...

Show Detail

python get unix timestamp given a timezone and datetime

is there a simplified way to get unix timestamp given a timezone and datetime using datetime and pytz? I searched some answers but not exactly this case. Given the moment datetime.datetime(2020, ...

Show Detail

Why do a timezone-unaware and a timezone-aware datetime object with a different timezone yield the same unix-timestamp?

So, as far as I understand if you convert without a timezone from or to a unix-timestamp you will always get GMT/UTC, like this: import datetime import pytz datetime.datetime(2020,4,1,0,0,0).times...

Show Detail

Convert unix timestamp in known timezone to datetime

I have a data download that supplies timestamps in unix form. They don't have any timezone awareness - they're simply a number - but they're localised to US/Pacific. I want to end up with them in E...

Show Detail

How convert dos datetime to Unix time?

Unix time is number seconds from beginning 1970 year. Java File time is number of milliseconds from 1970. Both Greenwich timezone. But dos datetime is bitfield format, several bits to day, month, y...

Show Detail

Conversion between Pandas Timestamp, DateTime, Unix Timestamp with Timezone / without Timezone Info

I created the following test case to understand the conversion of between DateTime to Pandas Timestamp, to Unix Timestamp, and back to DateTime, with and without TimeZone info, with Python 3.6 from

Show Detail

Converting SAS datetime to UNIX timestamp in SAS

I'm trying to convert a SAS datetime to a UNIX timestamp but am getting an 8 hour difference in my results. I think it's somehow related to a timezone issue but I can't figure out how. To start w...

Show Detail

Datetime returns wrong time in unix

I have a wired situation here with returning the time in unix format. I have this function: def get_today_date(): nowDate = str(datetime.datetime.utcnow().date()) unix_date = time.mktime(da...

Show Detail

Change datetime to Unix time stamp in Python

Please help me to change datetime object (for example: 2011-12-17 11:31:00-05:00) (including timezone) to Unix timestamp (like function time.time() in Python).

Show Detail