Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: add onclick event jquery button 
Javascript :: react add inline styles in react 
Javascript :: filter javascript 
Javascript :: js change value of every value in an object 
Javascript :: discord.js clean content 
Javascript :: wait function in javascript 
Javascript :: how to fill array with consecutive numbers javascript 
Javascript :: js check if is array 
Javascript :: ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @agm/core@1.1.0 npm ERR! Found: @angular/common@10.0.14 
Javascript :: find in array and change 
Javascript :: clear all intervals js 
Javascript :: javascript how to check if array is empty 
Javascript :: validate mobile number in javascript 
Javascript :: create function replace all n javescript 
Javascript :: joi custom error 
Javascript :: javascript sort numbers 
Javascript :: check if string contains lowercase javascript 
Javascript :: angular json to file and download 
Javascript :: javascript break for loop 
Javascript :: jquery wait for all ajax requests to complete 
Javascript :: formik validator in react 
Javascript :: how to cache data in javascript 
Javascript :: axios get data 
Javascript :: import modules js html 
Javascript :: javascript to remove few items from array 
Javascript :: filereader check file type 
Javascript :: add value to array javascript 
Javascript :: convert queryset to json django 
Javascript :: filter out undefined from object javascript 
Javascript :: get last word in string js 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =