Answers for "js Date(date).toLocaleString() MINUUTES"

0

js Date(date).toLocaleString() MINUUTES

var dt = new Date();
console.log(dt);
const localdte = dt.toLocaleString();
console.log(localdte);
const [dated, time, ampm] = localdte.split(' ');
const [hh, mm, ss] = time.split(':');
var date = `${
    dt.getDate().toString().padStart(2, '0')}/${
    (dt.getMonth()+1).toString().padStart(2, '0')}/${
    dt.getFullYear().toString().padStart(4, '0')} ${
    dt.getHours().toString().padStart(2, '0')}:${
    dt.getMinutes().toString().padStart(2, '0')}`
console.log("Date right now");
console.log(date);
console.log("date 15 mins later");

var date15 = `${
    dt.getDate().toString().padStart(2, '0')}/${
    (dt.getMonth()+1).toString().padStart(2, '0')}/${
    dt.getFullYear().toString().padStart(4, '0')} ${
    (dt.getMinutes()>44?(dt.hours==23?00:dt.getHours()+1):dt.getHours()).toString().padStart(2, '0')}:${
    ((dt.getMinutes()+15)%60).toString().padStart(2, '0')}`
console.log("24 hour format " + date15);
if (ampm == "PM" && hh != 12 && hh!=00) {
  var date15 = `${
    dt.getDate().toString().padStart(2, '0')}/${
    (dt.getMonth()+1).toString().padStart(2, '0')}/${
    dt.getFullYear().toString().padStart(4, '0')} ${
    (dt.getMinutes()>44?(dt.getHours()+1)%12:dt.getHours()%12).toString().padStart(2, '0')}:${
    ((dt.getMinutes()+15)%60).toString().padStart(2, '0')}`
  console.log("12 hour format " + date15 + ampm); //12 hour format
} else if (hh == 00) {
  var date15 = `${
    dt.getDate().toString().padStart(2, '0')}/${
    (dt.getMonth()+1).toString().padStart(2, '0')}/${
    dt.getFullYear().toString().padStart(4, '0')} ${
    (dt.getMinutes()>44?1:12).toString().padStart(2, '0')}:${
    ((dt.getMinutes()+15)%60).toString().padStart(2, '0')}`
  console.log("12 hour format " + date15 + ampm);
} else {
  console.log("12 hour format " + date15 + ampm); //12 hour format
}
const dateISO = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getHours(), ((dt.getMinutes() + 15) % 60), dt.getMilliseconds());
console.log("ISO 8601 format (UTC)");
console.log(dateISO);Create a snippet
Posted by: Guest on July-25-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language