Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Weird format Date to `toLocaleString` in javascript

I have an app that is currently running in Production. Suddenly, I have experienced a weird issue that I am not able to figure it out to prevent it. Any suggestion is highly appreciate.

This is the function where the error happened:

date_time: new Date(
                this.selectedDate.getFullYear(),
                this.selectedDate.getMonth(),
                this.selectedDate.getDate(),
                this.selectedHour.value.split(':')[0],
                this.selectedHour.value.split(':')[1],
                0
              ).toLocaleString(),

This date_time will be saved in database. Output Example: 12/9/2021, 2:00:00 PM. Everything is working as expected. However, today there is new record in database with different format: 12/9/2021 2:00:00 p.m. And it messed up my app. Do you know what happen to toLocaleString() ? Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since you tagged this angular I assume this code is running client-side and sending the resulting string to the server for insertion into your database.

toLocaleString converts a date to a string formatted for the user's locale.

It is designed to display a human readable date.

If a user with their system set to a different locale (likely because they are from a different country to you) then it will give different results.

If you want a standard date in a format that is easily machine processable (i.e. good for storing in a database) then use toISOString.

You can parse it and convert it to a local string for display later.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!