Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Como sacar el numero de dias de un mes

Hago un temporizador de cuenta regresiva, necesito tomar la cantidad de días en un mes y restar los días que han pasado (por ejemplo: 30 días de septiembre menos 8 días, la fecha es hoy). Ahora tengo que ingresarlo manualmente:

 const end = new Date(2021, 8, 30, 13, 0,12, 12);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede obtener el número de días en un mes usando:

 const getDays = (year, month) => new Date(year, month, 0).getDate() const days = getDays(2021, 8) console.log(days)

about 4 years ago · Juan Pablo Isaza Report

0

Días restantes en el mes actual

 var currentDate = new Date(); var currentYear = currentDate.getFullYear(); var currentMonth = currentDate.getMonth(); var currentMonthLastDate = (new Date(currentYear, currentMonth, 0)).getDate(); var daysLeftInMonth = currentMonthLastDate - currentDate.getDate(); console.log(daysLeftInMonth);

about 4 years ago · Juan Pablo Isaza Report

0

A) Si no solo obtiene la cantidad de días en un mes, intente con este:

 <script> function getDaysInMonth(month,year) { var today = new Date().getDate(); // Here January is 1 based // Day 0 is the last day in the previous month // var monthDays = new Date(year, month, 0).getDate(); // Here January is 0 based var monthDays = new Date(year, month+1, 0).getDate(); var remainDays = monthDays - today; return remainDays; } console.log(getDaysInMonth(8, 2021)); </script>

B) Si desea obtener un tiempo completo para seguir este:

 <div class="counter" style='color: green;'> <span class='em-days'>0</span> Days | <span class='em-hours'>8</span> Hours | <span class='em-minutes'>0</span> Minutes | <span class='em-seconds'>1</span> Seconds </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(function() { function getCounterTimerData(obj) { var days = parseInt($('.em-days', obj).text()); var hours = parseInt($('.em-hours', obj).text()); var minutes = parseInt($('.em-minutes', obj).text()); var seconds = parseInt($('.em-seconds', obj).text()); return seconds + (minutes * 60) + (hours * 3600) + (days * 3600 * 24); } function setCounterTimerData(s, obj) { var days = Math.floor(s / (3600 * 24)); var hours = Math.floor((s % (60 * 60 * 24)) / (3600)); var minutes = Math.floor((s % (60 * 60)) / 60); var seconds = Math.floor(s % 60); console.log(days, hours, minutes, seconds); $('.em-days', obj).html(days); $('.em-hours', obj).html(hours); $('.em-minutes', obj).html(minutes); $('.em-seconds', obj).html(seconds); } var count = getCounterTimerData($(".counter")); var timer = setInterval(function() { count--; if (count == 0) { clearInterval(timer); return; } setCounterTimerData(count, $(".counter")); }, 1000); }); </script>

Ahora puede configurar el día, los minutos y las horas manualmente

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!