How to find the first signs of the decade Luxon?

127 Views Asked by At

Luxon has start of day, year, etc., but how to find the first day of the decade?

2

There are 2 best solutions below

0
On BEST ANSWER

You can use the below code to achieve your purpose:

document.addEventListener('DOMContentLoaded', function() {
  const {
    DateTime
  } = luxon;

  // Get the current DateTime
  const now = DateTime.local();

  // Calculate the first year of the decade
  const firstYearOfDecade = now.year - (now.year % 10);

  // Create a new DateTime object with the first year of the decade, first month, and first day
  const firstDayOfDecade = DateTime.local(firstYearOfDecade, 1, 1);

  // You can use it print whatever you like
  console.log(`${firstDayOfDecade.toISODate()} - ${firstDayOfDecade.weekdayLong}`);


});
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/3.4.4/luxon.min.js" integrity="sha512-dUlSLLkxslGILhPdCkALwk4szPhp3xmZIKFtlUD+O9Lslq41Aksmdt5OGqpomDoT4FsCUH70jQU8ezZHI3v1RQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

0
On

By using this code.

const { DateTime } = require("luxon");
const currentDate = DateTime.now();
const firstDayOfDecade = currentDate.startOf("decade");

console.log("First day of the decade:", firstDayOfDecade.toISODate());`