Date and time dependant client server web apps - javascript

I read some articles regarding web applications which depend on the date and time and geographical position.
I am interested in finding here a few best practices and even solutions for java web applications which client side happens to be on Angular.
I am looking for the best way to store the dates and times in my database so that I can determine their values based on user's location. We have some help here from the Javascript side which can determine the user's timezone.
Any advices, best practices and solution would be great.
I want to know from your experience what is the best way to do this thing because each article I read had a slightly different solution and that small diference caused iasuea later.

You may want to check out Moment.js, and specifically the Timezone add-on if you haven't already... it will take ISO 8601 datetime formatted string by default, the industry standard on any platform.
The Timezone is useful in dealing with timezones and converting between them etc.
This format encodes the UTC time with a timezone part, with high precision.

Related

What is the most straightforward way to reformat all dates on my website?

I'm building a WordPress based site and the plugin that delivers the core-functionality doesn't allow changing the date format via the translation files.
All dates are giving out in an American format ("03-24-2017") and I would like to display them in a European format instead ("24.03.2017").
What would be the most straightforward and efficient way to do this? I googled the problem and found several JS-based libraries, but many of them seem to be to expansive (i.e. they also transform things like temperature, etc.). What I'm looking for is a straightforward solution that just formats the date and doesn't come with too much other technical hangover.
The straight forward way id, Go to Admin Panel, Open Settings, you can check Time Format
Choose Custom and add m.d.Y format.

SaaS Application and timezones

I have a multi tenant asp.net application. In it each user can set their timezone. However often users log in from browsers where the timezone is different to the preference they have set in my asp.net solution. I want to know, the best practise, should I always force the user to change his computer's timezone to that of his preference in my asp.net application
OR
Should I not bother and let him be in whichever timezone he is in? Any advice on the best practise or convention on how the big sites such as salesforce and others operate will be very helpful.
Tx
IMHO, you can save user preferences like timezone and show in the UI. If the user has no preference, use the UI culture to format the data for display in the UI.
Always store date times in db as UTC format and show in the UI based on the configuration or the current locale.
The JavaScript datetime formats are different from the C# formatting.
Please refer
https://msdn.microsoft.com/en-us/library/ff743760(v=vs.94).aspx
And, http://googleweblight.com/?lite_url=https://stackoverflow.com/questions/22096571/explanation-for-timespan-differences-between-c-sharp-and-javascript&ei=30ovNWzN&lc=en-IN&s=1&m=918&host=www.google.co.in&ts=1485879489&sig=AF9NedmhETXDK0ppwa-fSly3Hmy58wdNaw
HTH

Convert New York time to UTC using Javascript [duplicate]

Now, before you mark this as a duplicate, please note that all the useful answers in the possible duplicate provide functions which work in relation to the current system time, which I cannot accept.
What I want, is that the current time in, say, for example, New York, be consistent to all users, no matter what their time settings are.
For example, I have two computers here, and one is 3 seconds behind the other, and this leaves an unacceptable gap, as my task involve pinpoint precision (slightly exaggerated, but you know what I mean).
How can I overcome this? Must I get the server time and somehow convert it? If so, I'm using PHP.
Hope to not be wrong but javascript is loaded on user machine, not on the server so you will allway get the visitor date/time using javascript. you can use php to get the date/time because is loaded on the server and pass the dates to javascript.
Hope this help
You need to use a timezone library to do this in JavaScript. See my answer here.
The scripts are small, but because they require the timezone database, it can get unwieldy for a client application. You're probably better off doing the conversion server side. Perhaps the pytz library will be useful to you.

How to get the time of specific timezone using javascript, but without being relevant to the current system time?

Now, before you mark this as a duplicate, please note that all the useful answers in the possible duplicate provide functions which work in relation to the current system time, which I cannot accept.
What I want, is that the current time in, say, for example, New York, be consistent to all users, no matter what their time settings are.
For example, I have two computers here, and one is 3 seconds behind the other, and this leaves an unacceptable gap, as my task involve pinpoint precision (slightly exaggerated, but you know what I mean).
How can I overcome this? Must I get the server time and somehow convert it? If so, I'm using PHP.
Hope to not be wrong but javascript is loaded on user machine, not on the server so you will allway get the visitor date/time using javascript. you can use php to get the date/time because is loaded on the server and pass the dates to javascript.
Hope this help
You need to use a timezone library to do this in JavaScript. See my answer here.
The scripts are small, but because they require the timezone database, it can get unwieldy for a client application. You're probably better off doing the conversion server side. Perhaps the pytz library will be useful to you.

datejs vs Jquery/globalize

Could someone list the pros and cons of using one over the other. (www.datejs.com vs. https://github.com/jquery/globalize). All I knew is Jquery/globalize supports more culture than datejs.
You can use both of them together. DateJS makes it much more convenient to do math on date objects, and also provides some functionality for displaying dates. Globalize provides functionality for displaying dates for different cultures.
If you need to do math on dates and to display internationalized dates, use both. Have Globalize display dates that are calculated with DateJS.
If you just need to do math on dates and display dates in a format readable by most Internet users, use DateJS.
If you don't need to do math on dates (it might be that the server and APIs take care of it), but need to display internationalized dates, use Globalize.
Globalize supports more than just Date/Time formatting and Parsing (different Calendar systems with automatic conversion in the related field, number, currency, percentage formatting, translating strings, checking if given language is written Right-To-Left). It is fairly well-written and supports more than 350 culture. The project is quite active.
DateJS supports less cultures and only Date/Time formatting, parsing and manipulating as well as time zones conversion (unsupported by Globalize). The project is less active and the last snapshot is rather old (and marked as Alpha version). It seems like Joda Time equivalent for JavaScript and it really seems nice, but...
Fortunately, as Ben said you can combine them together.

Categories