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

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source