0

I want client system date and time format using javascript or jquery

Went i use this code

const dateTimeFormat = new Intl.DateTimeFormat();
const currentDateTime = new Date().toLocaleString(dateTimeFormat.resolvedOptions().locale);
console.log(currentDateTime);

4/24/2023, 2:42:38 PM it return this response

but my system display 24-04-2023 14:57

How to get saystem date and time format based on client system see this image

I Want -

Diff country use to show date and time format in diff format

like india - dd-mm-yyyy USA - mm-dd-yyyy

So i want to know what date and time format is used to display there device or window operating system to see date time


I want to retrieve the date and time format used by the client system using JavaScript or jQuery.

For example, when I use this code:

const dateTimeFormat = new Intl.DateTimeFormat(); const currentDateTime = new Date().toLocaleString(dateTimeFormat.resolvedOptions().locale); console.log(currentDateTime);

It returns a response in the format 4/24/2023, 2:42:38 PM, while my system displays 24-04-2023 14:57.

I want to obtain the date and time format based on the client system, as different countries use different formats, such as dd-mm-yyyy in India and mm-dd-yyyy in the USA.

How can I determine the date and time format used by the client's device or window operating system?

Justinas
  • 41,402
  • 5
  • 66
  • 96
  • What is "this format"? What keeps you from using any formatter for this, like for example explained in https://stackoverflow.com/questions/3552461/how-do-i-format-a-date-in-javascript? – Nico Haase Apr 24 '23 at 09:35
  • first check image , i want system date time format , but it return default javascript format , diff country have diff date time format display , so i want user system date time format , so i show date and time according to user view – Vikas Jindal Apr 24 '23 at 09:55
  • Please add all clarification to your question by editing it. Also, share all neccessary information **in text form** – Nico Haase Apr 24 '23 at 10:02
  • done , please check now – Vikas Jindal Apr 24 '23 at 10:10
  • Does this answer your question? [JavaScript - Get system short date format](https://stackoverflow.com/questions/16210058/javascript-get-system-short-date-format) – Justinas Apr 24 '23 at 10:35
  • these not provide system current format – Vikas Jindal Apr 24 '23 at 12:18
  • The `Intl.*` browser APIs use the *browser* language, not the *system* language. To my knowledge there is no possibility to get the system language from within the browser. – JSON Derulo Apr 24 '23 at 13:58

0 Answers0