Is there a way to adjust the navigator locale on a mobile device?

I'm currently testing out a utility function I created for displaying timestamps in a chat. My goal is to make it accessible worldwide and have it dynamically adjust based on the user's language settings.

However, I've run into some issues when trying to test it on mobile devices. On desktop, I can easily change the default language setting in Chrome's advanced options. Do you happen to know where this setting pulls from on mobile, and if it's possible to edit it there as well?

export function getLocaleTimestamp (showSeconds) {
  const locale = navigator.language || navigator.userLanguage;
  const date = new Date();
  let localeFormat = null;
  const options = {
    hour: 'numeric',
    minute: 'numeric',
    ...(showSeconds && { second: 'numeric' })
  };
  localeFormat = new Intl.DateTimeFormat(locale,
    options
  ).format;
  const formatedDate = localeFormat(date);
  return formatedDate;
}

Answer №1

A while back, I encountered a similar issue while testing a modification I made for one of our clients based in the USA. Chrome uses the timezone from the operating system, so to tackle this, I had to adjust the system date and time, and also establish a connection to a USA VPN. This led me to believe that it may consider the IP address being connected or the network timeline as well. You could also try using https://developers.google.com/web/tools/chrome-devtools/remote-debugging/ in Chrome dev tools with the following code: new Date().toLocaleString('en-US', { timeZone: 'Asia/Jakarta' }) //preferedtime zone

If you find any other solutions, please let me know. :) Here are some useful links: stackoverflow.com/a/16449343/1225070 and stackoverflow.com/a/18612568/1225070

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

PHP page Not Refreshing Properly Without Ajax

I am in need of assistance. Could someone please provide me with a code that has been thoroughly reviewed and tested for errors to address my issue? The program, 22.php, consists of a form. The desired functionality is for the user to enter information and ...

What causes errors in my AJAX request based on the particular file extension?

Utilizing JavaScript and jQuery, I have a function that loads data using $.get(url, function(response){ /* ... */});. The data is retrieved from a text file and handled within the response function of the JavaScript. Recently, I encountered an issue on my ...

Guide to implementing setTimeout in a .map() function in ReactJS

I am currently working on a project that involves an array of players. Whenever a user adds a new player to this array, I need it to be displayed one at a time with a 500ms interval between each player. Below is the code snippet I have written for this f ...

Tips for maintaining a marker at the bottom of the screen while zooming, similar to Google Maps

Is there a way to customize the zoom behavior in my project? I want to maintain the bottom position while resizing the other three directions, and also include pitch adjustments. https://i.sstatic.net/hQdg8.gif https://i.sstatic.net/m3xef.gif I aim for t ...

I wonder, who is the one executing the function?

In my application, I have encountered an unusual issue. Within my controller, I have two functions - one to add a tab, and one to remove a tab. Below is the code snippet: $scope.createTab = function(){ $scope.addTab("New Tab",50,0); co ...

Margin ambiguity in a vue.js application

I am facing an issue with my Vue.JS project setup. I want the App.vue to occupy the entire page and have different routes displayed within App.vue using router-view. But, when I try to add a margin to the content of my Game component, the margin seems to ...

Using Javascript and jQuery to convert text into a tag

I'm attempting to use JavaScript to send a message on twitch.tv by modifying the textarea in the chatbox. <textarea class="tw-textarea tw-textarea--no-resize " placeholder="Send message" data-a-target="chat-input" data-test-selector="chat-input" s ...

Browsing JSON data to pinpoint locations on a Google map

Trying to create a google map using jQuery and javascript with latitude and longitude values stored in a JSON file. Clicking on a state name should generate the map. Encountering an issue where only index[0] is being generated. The for loop seems to be ma ...

Guide to using Ajax to load a partial in Ruby on Rails

Whenever a search is triggered, I have a partial that needs to be loaded. This partial can take a significant amount of time to load, so I would prefer it to be loaded via Ajax after the page has fully loaded to avoid potential timeouts. Currently, my app ...

Achieving successful implementation of SSAO shader on SkinnedMesh models

Trying to implement the SSAO post-processing shader with the most recent version (r77) of three.js has been a challenge for me. I have been utilizing the EffectComposer, with the code completely replicated from the example page provided here: The specific ...

Real-time updates for UI data in Next.js Firestore are not being reflected

I'm currently working on implementing real-time changes using nextjs and Firebase Firestore. However, I've noticed that I still need to refresh the page in order for the updates to be visible. const [getUsers, setUsers] = useState(""); const che ...

Mastering the Art of Promises in RXJS Observables

After thoroughly researching SO, I stumbled upon numerous questions and answers similar to mine. However, I suspect that there might be gaps in my fundamental understanding of how to effectively work with this technology stack. Currently, I am deeply enga ...

Selenium and AngularJS patiently wait before carrying out specific actions

I have been using selenium to test an AngularJS application and I am encountering an issue where I am unable to perform any actions on the page until it is fully loaded. Although I have considered using Thread.sleep(), I am aware that this is not the most ...

Exploring AngularJS to search for and present data in a tabular layout

Can anyone guide me on searching for data within a JSON file and presenting it in a table format? I want the table to be visible only when I click the search button. I would really appreciate it if someone could provide me with instructions or a helpful ...

Steps for connecting html to an external component in Angular

We have included an external library in our project that contains various components. One of the components is an alert modal, which is used like this: <alert dismissible="false">Enter your text here</alert> When rendered, it looks like this: ...

Tips on creating a transition in React to showcase fresh HTML content depending on the recent state changes

I am completely new to React and recently completed a project called Random Quote Machine. The main objective was to have a method triggered inside React when the user clicks a button, changing the state value and re-rendering to display a new quote on the ...

Is there a way to iterate through this?

I have data that I need to loop over in JavaScript. Since it is not an array, the map function is not working. Can someone help me loop over it or convert it into an array so that I can iterate through it? { "7/15/2021": { "date": ...

Discover a revolutionary Android app that provides detailed indoor maps and step-by-step walking directions

I am looking to enhance a custom Google map by adding sidewalks for walking, while keeping all of its original features intact. Additionally, I want to create a detailed interior map of a building on a college campus, complete with classroom locations on ...

Discover the versions of key libraries/modules within the webpack bundle

Is it possible to identify all the libraries, scripts, or modules included in a webpack bundle through the developer's console of a website that is already running, without access to its codebase? Additionally, is there a way to determine the version ...

Effortless Numerical Calculation for Trio Input Fields

I am in the process of setting up three numeric input fields that will automatically calculate and display results on the side. I am struggling with this task as I am not familiar with using ajax. Can someone assist me in implementing this functionality us ...