0

Before you read this question. I assume that the main answers will be "No you cant. For X reasons"

I'm just asking the question after long investigation and found nothing about it. So who knows. I might get some answers here for what I'm looking to

Question: I want to get the OS language or date / time formatting from the javascript / typescript. I don't want to use the browsers locale. How can I do that, if it's possible?

Environment:

  • Angular SPA app
  • Support for different date / time format depending of user locale

Current status: Web app in which we format the dates depending of users locale (getting it from browsers culture)


Wanted status:

Same but we get the locale / date & time format from the OS of the user


Why ?

Because we develop an app, which our customers might be users that CAN'T change their settings of the browser, but they could of their OS.

So for consistency, we would like to use the OS settings

mmonteirocl
  • 382
  • 2
  • 16
  • What is the question? There's only one questionmark in your whole text, and that is in your _"Why?"_-title... I only read a lot of status/why etc. but no actual question. Skip the nonsense and just formulate a good question. You might get the answer you don't want, but at least you'll know why..? – Daniel B Aug 20 '21 at 13:37
  • @DanielB. I added the question it-self. Please re-read the post – mmonteirocl Aug 20 '21 at 13:39
  • 1
    AFAIK, if you change your OS settings, it will also impact the browser. Also, it is usually geographically based if I'm not mistaken. – kissu Aug 20 '21 at 16:48
  • @kissu—not necessarily. There is no standard for where regional settings such as date formats come from, every implementation I know of uses only language (misnamed "locale" by ECMA-402). Some browsers have their own settings for language, and even those that do, don't necessarily use them for date formatting, they're used for translating pages, spell and grammar checks, etc. – RobG Aug 20 '21 at 23:29
  • The only sensible way to do this is to have preferences within your app for the user to set formats. They do not necessarily want the same format in your app as they want for dates displayed by the OS, and likely don't want to change their OS settings to get the right format in your app. Preferred format can also depend on context, e.g. tabulated dates might be preferred as 2021-08-21, but the same date in text as 21 August, 2021. – RobG Aug 20 '21 at 23:35
  • Probably a duplicate of [*Retrieve OS Date formatting*](https://stackoverflow.com/questions/15834855/javascript-retrieve-os-date-formatting) and [*How do I format a Date object with users preference instead of locale?*](https://stackoverflow.com/questions/60638746/how-do-i-format-a-date-object-with-users-preference-instead-of-locale) – RobG Aug 20 '21 at 23:37
  • @RobG Agreed thats the best way. But still we would like to use the default one (until user modifies them) the ones of the OS – mmonteirocl Aug 23 '21 at 14:53

0 Answers0