You will need to create a function to extract the date parts and use them with the Date constructor.

Note that this constructor treats months as zero based numbers (0=Jan, 1=Feb, ..., 11=Dec).

For example:

function parseDate(input) {
  var parts = input.match(/(\d+)/g);
  // note parts[1]-1
  return new Date(parts[2], parts[1]-1, parts[0]);
}

parseDate('31.05.2010');
// Mon May 31 2010 00:00:00

Edit: For handling a variable format you could do something like this:

function parseDate(input, format) {
  format = format || 'yyyy-mm-dd'; // default format
  var parts = input.match(/(\d+)/g), 
      i = 0, fmt = {};
  // extract date-part indexes from the format
  format.replace(/(yyyy|dd|mm)/g, function(part) { fmt[part] = i++; });

  return new Date(parts[fmt['yyyy']], parts[fmt['mm']]-1, parts[fmt['dd']]);
}

parseDate('05.31.2010', 'mm.dd.yyyy');
parseDate('31.05.2010', 'dd.mm.yyyy');
parseDate('2010-05-31');

The above function accepts a format parameter, that should include the yyyy mm and dd placeholders, the separators are not really important, since only digits are captured by the RegExp.

You might also give a look to DateJS, a small library that makes date parsing painless...

Answer from Christian C. Salvadó on Stack Overflow
🌐
FreeFormatter
freeformatter.com › germany-standards-code-snippets.html
Formatting standards & code snippets for Germany - Freeformatter.com
Locale locale = new Locale("de", ... DateTime.Now.ToString("yyyy-MM-dd", ci); // or dd.MM.yyyy · let date = new Date(); date.toLocaleDateString('de-DE', {year: 'numeric', month: '2-digit', day:'2-digit'}); // in order to get yyyy-MM-dd format, use date.toISOString().substring(0, ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › parse
Date.parse() - JavaScript | MDN
The formats that parse() can handle are not explicitly specified, but there are a few invariants: The date time string format (produced by toISOString()) must be supported.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleDateString
Date.prototype.toLocaleDateString() - JavaScript | MDN
The toLocaleDateString() method of Date instances returns a string with a language-sensitive representation of the date portion of this date in the local timezone. In implementations with Intl.DateTimeFormat API support, this method delegates to Intl.DateTimeFormat.
🌐
openHAB Community
community.openhab.org › setup, configuration and use › items & sitemaps
How convert a german date string to datetime format - Items & Sitemaps - openHAB Community
April 1, 2020 - Platform information: Hardware: Pi3 OS: Raspbian Buster Java Runtime Environment: Java™ SE Runtime Environment (build 1.8.0_201-b09) openHAB version: 2.5.2-1 Hi, i read via regex a date string in format “01.04.2020 07:39:48” (german date format) from a website.
🌐
Day.js
day.js.org › docs › en › parse › string-format
String + Format · Day.js
Pass the locale key as the third parameter to parse locale-aware date time string. require('dayjs/locale/es') dayjs('2018 Enero 15', 'YYYY MMMM DD', 'es') You may specify a boolean for the last argument to use strict parsing. Strict parsing requires that the format and input match exactly, including delimiters.
Find elsewhere
🌐
Moment.js
momentjs.com › docs
Moment.js | Docs
For these reasons, we agree with MDN's statement that parsing strings with the Date object is strongly discouraged. Modern JavaScript environments will also implement the ECMA-402 specification, which provides the Intl object, and defines behavioral options of the Date object's toLocaleString, toLocaleDateString, and toLocaleTimeString functions.
🌐
W3Schools
w3schools.com › jsref › jsref_tolocalestring.asp
JavaScript Date toLocaleString() Method
new Date() constructor getDate() getDay() getFullYear() getHours() getMilliseconds() getMinutes() getMonth() getSeconds() getTime() getTimezoneOffset() getUTCDate() getUTCDay() getUTCFullYear() getUTCHours() getUTCMilliseconds() getUTCMinutes() getUTCMonth() getUTCSeconds() now() parse() prototype setDate() setFullYear() setHours() setMilliseconds() setMinutes() setMonth() setSeconds() setTime() setUTCDate() setUTCFullYear() setUTCHours() setUTCMilliseconds() setUTCMinutes() setUTCMonth() setUTCSeconds() toDateString() toISOString() toJSON() toLocaleDateString() toLocaleTimeString() toLocaleString() toString() toTimeString() toUTCString() UTC() valueOf() JS Function
Top answer
1 of 2
4

Formatting of javascript dates is covered in numerous other questions. A particular timezone can be specified using the timeZone option with toLocaleString or for more control use the Intl.DateTimeFormat constructor and format option (timezones are specified using an IANA representative location to apply historic and DST changes), e.g.

let d = new Date();

// toLocaleString, default format for language de
console.log(d.toLocaleString('de',{timeZone:'Europe/Berlin', timeZoneName: 'long'}));

// DateTimeFormat.format with specific options
let f = new Intl.DateTimeFormat('de', {
  year: 'numeric',
  month: 'short',
  day: 'numeric',
  hour: '2-digit',
  hour12: false,
  minute: '2-digit',
  timeZone: 'Europe/Berlin',
  timeZoneName: 'short'
});
console.log(f.format(d));

You might also be interested in this answer.

2 of 2
2

You could use native JavaScript functions to convert (toLocaleString), or you could use moment timezone (which is more flexible).

For the toLocaleString call I'm also specifying a Germany date format (by passing "de-DE" to the locale parameter, you could use whichever locale you wish.

function getGermanDate(input) {
    return moment.tz(input, "Europe/Berlin");
}

/* Using moment timezone */
let timestamp = "2020-08-12 23:00:00";
let timeIndia = moment.tz(timestamp, "Asia/Kolkata");
let timeGermany = getGermanDate(timeIndia);
console.log("Time (India):", timeIndia.format("YYYY-MM-DD HH:mm"));
console.log("Time (Germany):", timeGermany .format("YYYY-MM-DD HH:mm"));

/* Using native JavaScript */
let dateToConvert = new Date("2020-08-12T23:00:00+0530");

console.log("Time (India, native):", dateToConvert.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }));
console.log("Time (Germany, native):", dateToConvert.toLocaleString('de-DE', { timeZone: 'Europe/Berlin' }));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.25/moment-timezone-with-data-10-year-range.js"></script>

🌐
Webdevtutor
webdevtutor.net › blog › javascript-date-parse-locale-string
Understanding JavaScript Date Parsing with Locale String
Let's look at a practical example of parsing a date string in German locale format: javascript const germanDate = '24.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Intl › DateTimeFormat
Intl.DateTimeFormat - JavaScript | MDN
The initial value of the [Symbol.toStringTag] property is the string "Intl.DateTimeFormat". This property is used in Object.prototype.toString(). ... Getter function that formats a date according to the locale and formatting options of this DateTimeFormat object.
🌐
Byby
byby.dev › js-format-date
How to parse and format a date in JavaScript
In addition to supporting a wide range of date formats, they also offer features like fuzzy parsing, which can interpret partial or ambiguous dates based on context. Once a date is parsed in JavaScript and converted to a Date object, it can then be formatted into a string with a specific date format.
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
Independent of input format, JavaScript will (by default) output dates in full text string format:
🌐
Moment.js
momentjs.com
Moment.js | Home
moment.locale(); moment().format('LT'); moment().format('LTS'); moment().format('L'); moment().format('l'); moment().format('LL'); moment().format('ll'); moment().format('LLL'); moment().format('lll'); moment().format('LLLL'); moment().format('llll');
🌐
GitHub
github.com › iamkun › dayjs › issues › 1324
13. Oktober 2020 is an invalid date · Issue #1324 · iamkun/dayjs
August 6, 2020 - Describe the bug Parsing 13. Oktober 2020 with the German locale gives me back an invalid date. import dayjs from 'dayjs'; import * as DAYJS_LOCALE_DE from 'dayjs/locale/de'; dayjs.locale(DAYJS_LOCALE_DE); const dayjsDate = dayjs("13. Ok...
Author   alexander-fischer