“Data JavaScript do formatu ciągu” Kod odpowiedzi

Data JavaScript do ciągu

// 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 Conwert datę na yyyy-mm-dd

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

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

Data JavaScript do formatu ciągu

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

Konwertuj datę na format ciągu DD/mm/tys. 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

Data formatu 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

Data formatu 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

Odpowiedzi podobne do “Data JavaScript do formatu ciągu”

Pytania podobne do “Data JavaScript do formatu ciągu”

Więcej pokrewnych odpowiedzi na “Data JavaScript do formatu ciągu” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu