ProgramsJavaScript

JavaScript Date and Time Programs

Work with dates and times in JavaScript. Get the current time, format dates, add days, compare dates, build timers and handle time zones, with sample output.

10 programs · open one, then the next

Start with Get Current Date and Time
  1. 01Get Current Date and TimeBeginnerGet the current date and time in JavaScript with new Date(), getters, ISO, locale and UTC methods, timestamps and a custom format. Explanation and output.Open example →
  2. 02Format Date and TimeBeginnerFormat dates in JavaScript as YYYY-MM-DD, DD/MM/YYYY and DD MMM YYYY, show relative time like "1 hours ago", and use Intl locales. Explanation and output.Open example →
  3. 03Date ArithmeticBeginnerAdd and subtract days, months, years and hours in JavaScript with set methods and timestamps, and find date differences. Explanation and output.Open example →
  4. 04Compare DatesBeginnerCompare dates in JavaScript with getTime(), < and >, range checks, is-today, past or future checks and date-only checks. Explanation and output.Open example →
  5. 05Timezone ConversionIntermediateConvert time zones in JavaScript with getTimezoneOffset, UTC, toLocaleString and Intl.DateTimeFormat. Store UTC, show local. Explanation and output.Open example →
  6. 06Countdown TimerIntermediateCalculate remaining time until a target date in JavaScript with Date and a CountdownTimer class. Convert milliseconds to days and stop when the target expires.Open example →
  7. 07StopwatchIntermediateMeasure elapsed time in JavaScript with Date.now and a Stopwatch class. Format durations, resume saved time, and record laps; interval ticks can be delayed.Open example →
  8. 08Calculate AgeBeginnerCalculate age from a birthdate in JavaScript: whole years, years-months-days, age in other units, next birthday and days left until it. Explanation and output.Open example →
  9. 09Date ValidationBeginnerValidate dates in JavaScript: catch Invalid Date with isNaN, check YYYY-MM-DD format, ranges, past and future, and reject 30 February. Explanation and output.Open example →
  10. 10Date UtilitiesBeginnerWrite JavaScript date utilities: start and end of day, week, month and year, days in a month, leap years and weekend checks. Explanation and output.Open example →