How to convert time zone from digits/numbers to date openweathermapAPI - javascript

I am using openweathermap API, I am trying to fetch the timezone. The api have timezone as: 34200. How can I convert it to date format? I am using javascript.
I am new to it, so I am not sure where to start. I even looked up, but couldn't find any solutions.

It's how much the time has shifted in seconds from the UTC, so 34200 means 9,5 hours to the east. So this one would probably be somewhere in china. If you need help with the code, just say so, I can help you with the code too. But I think this answers your question

You can use moment library for convert time or date. It is very easy to understand and implement.

Related

Save time of day as number in mongodb, but display in a human format (using meteor autoform)

In a form, I'm asking for a start time & end time, which I'll be using in a script later on.
I figured in MongoDB, a time of day is best stored as the # of seconds since midnight (per How can I store time-of-day in MongoDB? As a string? Give arbitrary year/month/day?).
My question is: how can I display a human-readable time in autoform (e.g. 7:30pm) yet still save it as a number in mongodb & have proper client-side validation (make sure time is before 8:00pm)? I figure I could either use a datetime object & subtract the seconds since 1970, or I could parse the time string & do math on the hours, minutes, AM/PM.
Thoughts on methods? & where to put the math hooks in autoform? This seems like something folks a lot smarter than me have probably already figured out!
new Date(<unixTimeStamp>) will get you a javascript Date object which can be easily played with using libraries like moment (https://github.com/moment/moment)
Edit: also, to get the proper timestamp you can do +Date.now(). This jives with mongodb's date type

Moment timezone does not return correct time

So I am currently in the "America/Los_Angeles" timezone (PDT), but when I create a new moment object and pass it through moment tz to set its timezone to the very one I'm in ('America/Los_Angeles'), like so:
moment().tz("America/Los_Angeles");
the wrong time is being returned. Specifically, it's 8 hours ahead. This happens for all other timezones I try as well.
Am I just fundamentally misunderstanding how this is supposed to work?
Thanks for any help!
When I replaced your copy of moment-timezone.js with the one from the web site, it returned the correct result.
You need to use "zone" you pass it an offset off GMT.
moment().zone(-8)

Strange javascript Date toISOString

I am using fullcalendar for a project of mine. I have a strange problem that keeps bugging me. When I export an event, I want to get it in timestamp format, which is OK. the problem is when I try to convert it to ISO format using Date.toISOString function, it gives me the time 2 hours earlier. I think it is a problem of my timezone, because I posted my timestamp on http://www.unixtimestamp.com/ and it gives me the right time, but when I do it in my browser, it gives me the date and time with 2 hours earlier. I can't seem to figure it out. I googled a lot for a solution, but nothing so far. Does anybody have a clue?
toISOString will give you a string to represent the time in UTC. If you look at the result closely enough, you can find there is a "Z" in the end, which means the timezone is UTC.

Denerate date time by passing time zone in javascript

My requirement is to get the date and time by passing the timezone using the javascript.
Is there any javascript function by which i can achieve this?
it can get pretty complicated but there is a good js library you can use
https://bitbucket.org/pellepim/jstimezonedetect/wiki/Home

Should I use getHours() or getUTCHours for my Javascript?

I want to get the time on the computer of the person who is accessing my website. Should I use getHours() or getUTCHours()?
Short answer is it depends. If you want the hours as it displays on a clock for their timezone you will want getHours() as it returns the hours in their local time. If you want the hours in Universal Time (no timezone adjustment) then use getUTCHours()
I would recommend getUTCHours - keeping everything in UTC removes a lot of headaches when it comes to working with dates and times.
getHours will return the time according to their timezone, getUTCHours will get their time converted to UTC. Would probably be easier to use getUTCHours so everyone is returning their time in the same timezone.
It depends what you're using it for. If you want to get the user's local time, use getHours(). If you want to get something like a time offset (say, "hours until the new CoD is released in the UK"), use getUTCHours() as an absolute reference point. Bear in mind, however, that if the user's clock is set wrong, getUTC*() functions will return times that aren't really UTC - all they do really is remove the getGMTOffset() amount for you.
It depends on what you want to do, but i'd agree with Andrew, if you use getUTC*** it becomes easier for you to handle dates and times

Categories

Resources