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

107
Views
MomentJS convert localized date to UTC

I'm currently having the following date string in german format:

01.09.2021, 14:28:53 // which means the 1st of September, 2021

and I try to parse it to UTC, but unfortunatelly when I do it, it switches days with months.

2021-01-09T14:28:53.000Z

The code that I have:

const date: string = '01.09.2021, 14:28:53';
moment.utc(date).locale('de').toISOString();

What I try to achieve is:

2021-09-01T14:28:53.000Z
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Pass your custom format

const date = '01.09.2021, 14:28:53';
const tmp = moment(date, 'DD.MM.YYYY, HH:mm:ss').locale('de').toISOString();
console.log(tmp);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report

0

No need for moment

const de = true; // as opposed to en = true;
const str = `01.09.2021, 14:28:53`
const [_,aa,bb,yyyy,t] = str.split(/(\d{2})\.(\d{2})\.(\d{4}), (\d{2}\:\d{2}\:\d{2})/)
dd = de ? aa : bb;
mm = de ? bb : aa;
console.log(dd,mm,yyyy,t);
console.log(`${yyyy}-${mm}-${dd}T${t}.000Z`);

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!