Denerate date time by passing time zone in javascript - 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

Related

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

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.

Displaying Different Time-Zone in Single HTML Page

I want do display Dates from different time-zone (PDT, IST, JST and AEST) on single HTML page. I'm not very proficient in JavaScript learning currently. Any help is really appreciated.
In case you want to display current date, the javascript Date() will automatically get the date based on local timezone.
var date = new Date();
You can also refer to all the methods javascript date supports here -> https://www.w3schools.com/jsref/jsref_obj_date.asp
Best way to handle dates is by using moment library
https://momentjs.com/timezone/

JS native format date method

I've got trivial question for which I can't find simple answer - how can I format Date object in order to get it in format I need? For example, "20.01.2014". I know about moment.js library but I must do it using only native JS. Please, give me answer. Thanks!
You use the getHours, getMinutes, and getSeconds (or getUTCHours, getUTCMinutes, and getUTCSeconds) methods on your Date instance, which give you numbers, and then do the formatting with string manipulation.

Date and time without timestamp in Javascript

In Javascript I need to work with the concepts of date, time and "date and time " without referring to a particular point in time. This is exactly the same semantics that joda time's LocalDate and LocalTime provide in Java. I've been briefly looking at Date.js and moment.js, but both libraries seem to build on the Date object, which represents a point in time. Is there any javascript library that provides what I need?
Use case:
There is a model entity -a coupon- which has an expiration date (joda time's LocalDate). I want to compare that date with today's date, so I need a representation of today's date (actually a string in yyyy-mm-dd format would do). I know that today's date, and hence the result of the comparison too, will depend on the timezone settings of the browser's but that's not a problem.
I've started a few times on a JavaScript library with similar API to Noda Time / Joda Time / Java 8. I definitely see value in that. However, there's nothing out there as of yet, as far as I know. There are other reasons that make the Date object less than ideal. I'll try to remember to update this post when/if I ever get a new library off the ground, or if I learn of one created by someone else.
In the mean time, the easiest thing would be to use moment.js:
var expDateString = "2015-06-30";
var exp = moment(expDateString, "YYYY-MM-DD");
var now = moment();
if (exp.isAfter(now))
// expired
else
// valid
You could also do this with plain JavaScript, but there are some gotchas with parsing behavior. Moment is easier.

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