Luxon snippets

by Raul Bojalil

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/3.0.1/luxon.min.js"></script>

JavaScript

//DateTime Format Presets:
//https://github.com/moment/luxon/blob/master/docs/formatting.md#presets

/*alert(
	"With minutes: " + luxon.DateTime.fromISO("2023-02-03T00:12:00").diffNow('minutes').minutes +
	" With no minutes: " + luxon.DateTime.fromISO("2023-02-03T00:12:00").diffNow('minutes')
 );*/

console.log(luxon.DateTime.fromISO("2023-01-01T00:00:00.000-06:00").plus({ minutes: 10 }).setLocale('es').setZone('America/Mexico_City').toFormat('HH:mm'));

//console.log(luxon.DateTime.fromISO("").toLocaleString() == 'Invalid DateTime')
 
/*console.log(luxon.DateTime.now().setLocale('es').setZone('America/Mexico_City').toLocaleString({
    day: 'numeric',
    hour: 'numeric',
    minute: '2-digit',
    month: 'numeric',
    timeZoneName: 'short',
    year: 'numeric',
  }));*/
//console.log(luxon.DateTime.TIME_WITH_SHORT_OFFSET)

const formatDate = (date) => {
  const dateTime = luxon.DateTime.fromJSDate(date);
  return dateTime.setLocale('en').setZone('US/Central').toLocaleString({
    day: 'numeric',
    hour: 'numeric',
    minute: '2-digit',
    month: 'numeric',
    timeZoneName: 'short',
    year: 'numeric',
  });
}

var date = new Date("2023-06-07T18:40:43.447Z");
console.log(luxon.DateTime.fromJSDate(date).setLocale('es').setZone('America/Mexico_City').toFormat("yyyy-MM-dd'T'HH:mm':00.000-06:00'"))

//const dateTime = luxon.DateTime.fromJSDate(date);

//console.log(formatDate(date));


//Current date
//console.log(luxon.DateTime.now().toLocaleString(luxon.DateTime.DATETIME));
//console.log(luxon.DateTime.local().toLocaleString(luxon.DateTime.DATETIME));
//console.log(luxon.DateTime.fromJSDate(new Date()).toLocaleString(luxon.DateTime.DATETIME));

//local
//console.log(luxon.DateTime.local(2017, 3, 12, 5,...