Reputation: 47
I am using https://openweathermap.org/current api and i want to get current date and time of the target city, I am getting timezone (shift in seconds from UTC) value from api, so how can i get the current time using this timezone offset value.
Lets suppose I have received this below timezone offset value from api
const timezone = -14400
Upvotes: 1
Views: 3067
Reputation: 47
const timezone = -14400 //needs to be converted in minutes
const timezoneInMinutes = timezone / 60;
const currTime = moment().utcOffset(timezoneInMinutes).format("h:mm A");
// 10:10 PM
Upvotes: 2
Reputation: 203482
const dt = 1593674356; // unix timestamp in seconds
const timezone = 3600; // zone in seconds
// moment.unix - Unix Timestamp (seconds)
const dateTime = moment.unix(dt).utc().add(timezone, 's');
console.log(dateTime);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js"></script>
Upvotes: 0