Search code examples
javascriptluxon

How to find the first signs of the decade Luxon?


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


Solution

  • 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>