“JavaScript -Datum zum Zeichenfolgeformat” Code-Antworten

JavaScript -Datum der Zeichenfolge

// There are two flavours
const event = new Date(1993, 6, 28, 14, 39, 7);

// The Old Skool Flava
console.log(event.toString());
// expected output: Wed Jul 28 1993 14:39:07 GMT+0200 (CEST)
// (note: your timezone may vary)

// The Hipster way ;)
console.log(event.toDateString());
// expected output: Wed Jul 28 1993
Kaotik

JavaScript konvertieren Datum in Yyyy-MM-DD

// `date` is a `Date` object
const formatYmd = date => date.toISOString().slice(0, 10);

// Example
formatYmd(new Date());      // 2020-05-06
Batman

JavaScript -Datum zum Zeichenfolgeformat

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today  = new Date();

console.log(today.toLocaleDateString("en-US")); // 9/17/2016
console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
console.log(today.toLocaleDateString("hi-IN", options)); // शनिवार, 17 सितंबर 2016
Spongey Bob

Konvertieren Sie das Datum in Stringformat DD/MM/JJJJ JavaScript

// Convert Date.now() to Formatted Date in "dd-MM-YYYY".
function convertDate(inputFormat) {
  function pad(s) { return (s < 10) ? '0' + s : s; }
  var d = new Date(inputFormat)
  return [pad(d.getDate()), pad(d.getMonth()+1), d.getFullYear()].join('-')
}

console.log(convertDate('Mon Nov 19 13:29:40 2012')) // => "19-11-2012"
The Ultimate Karam

Formatdatum js

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today  = new Date();

console.log(today.toLocaleDateString("en-US")); // 9/17/2016
console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016

 // For custom format use
 date.toLocaleDateString("en-US", { day: 'numeric' })+ "-"+ date.toLocaleDateString("en-US", { month: 'short' })+ "-" + date.toLocaleDateString("en-US", { year: 'numeric' }) // 16-Nov-2019
Nemesis

Formatdatum js

const t = new Date();
const date = ('0' + t.getDate()).slice(-2);
const month = ('0' + (t.getMonth() + 1)).slice(-2);
const year = t.getFullYear();
const hours = ('0' + t.getHours()).slice(-2);
const minutes = ('0' + t.getMinutes()).slice(-2);
const seconds = ('0' + t.getSeconds()).slice(-2);
const time = `${date}/${month}/${year}, ${hours}:${minutes}:${seconds}`;

output: "27/04/2020, 12:03:03"
Drab Dingo

Ähnliche Antworten wie “JavaScript -Datum zum Zeichenfolgeformat”

Fragen ähnlich wie “JavaScript -Datum zum Zeichenfolgeformat”

Weitere verwandte Antworten zu “JavaScript -Datum zum Zeichenfolgeformat” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen