Get the Current Date in TypeScript: Multiple Methods Explained

Recently, I was working on a TypeScript project where I needed to manipulate dates for a scheduling application. The task was simple: getting the current date in TypeScript. In this tutorial, I will explain how to get the current date in TypeScript using various methods.

Using the Native Date Object

The best way to get the current date in TypeScript is using JavaScript’s built-in Date object. I use this method frequently for simpler projects.

// Get current date and time
const currentDate: Date = new Date();
console.log(currentDate); // Outputs the full date and time

// Get only today's date (without time)
const today: Date = new Date();
today.setHours(0, 0, 0, 0);
console.log(today); // Outputs today's date with time set to midnight

// Format as MM/DD/YYYY (US format)
const formattedDate: string = `${currentDate.getMonth() + 1}/${currentDate.getDate()}/${currentDate.getFullYear()}`;
console.log(formattedDate); // Outputs something like 04/24/2025

The Date object is available in all JavaScript environments, so you don’t need to install any additional packages. However, formatting options are limited, and you’ll need to write your own formatting logic.

You can see the exact output in the screenshot below:

Get the Current Date in TypeScript

One thing to note is that months in JavaScript are zero-indexed (January is 0, December is 11), which is why I add 1 when formatting the month.

Check out Add Months to a Date in TypeScript

Using the date-fns Library

When I’m working on larger projects that need more sophisticated date handling, I prefer using date-fns. It’s lightweight, modular, and follows functional programming principles.

First, install date-fns:

npm install date-fns

Then you can use it in your TypeScript code:

import { format, startOfDay } from 'date-fns';

// Get current date and time
const currentDate: Date = new Date();
console.log(currentDate);

// Get only today's date (start of day)
const today = startOfDay(new Date());
console.log(today);

// Format date in various ways
const formattedDate = format(currentDate, 'MM/dd/yyyy');
console.log(formattedDate); // Outputs like 11/22/2023

// More formatting examples
console.log(format(currentDate, 'MMMM d, yyyy')); // November 22, 2023
console.log(format(currentDate, 'EEEE, MMMM do, yyyy')); // Wednesday, November 22nd, 2023

What I love about date-fns is that it’s tree-shakable, meaning you only import what you need, keeping your bundle size small.

Using moment.js

While moment.js is somewhat deprecated for new projects (in maintenance mode), many existing projects still use it. If you’re working with a codebase that already has moment.js, here’s how to use it:

npm install moment
import moment from 'moment';

// Get current date and time
const currentMoment = moment();
console.log(currentMoment.toDate());

// Get only today's date (start of day)
const today = moment().startOf('day');
console.log(today.toDate());

// Format date in various ways
console.log(currentMoment.format('MM/DD/YYYY')); // 11/22/2023
console.log(currentMoment.format('MMMM D, YYYY')); // November 22, 2023
console.log(currentMoment.format('dddd, MMMM Do YYYY')); // Wednesday, November 22nd 2023

Moment.js has excellent formatting capabilities and timezone handling, but it’s larger than alternatives like date-fns.

Check out Create a Date from Year, Month, and Day in TypeScript

Using Intl.DateTimeFormat

For applications that need to support internationalization, the built-in Intl.DateTimeFormat is an excellent choice:

// Get current date
const currentDate: Date = new Date();

// Format date for US locale
const usFormatter = new Intl.DateTimeFormat('en-US', {
  year: 'numeric',
  month: '2-digit',
  day: '2-digit'
});
console.log(usFormatter.format(currentDate)); // Outputs like 04/24/2025

// Format with more options
const detailedFormatter = new Intl.DateTimeFormat('en-US', {
  weekday: 'long',
  year: 'numeric',
  month: 'long',
  day: 'numeric'
});
console.log(detailedFormatter.format(currentDate)); // Thursday, April 24, 2025

// Supporting different locales
const frenchFormatter = new Intl.DateTimeFormat('fr-FR', {
  year: 'numeric',
  month: 'long',
  day: 'numeric'
});
console.log(frenchFormatter.format(currentDate)); // 24 avril 2025

This method is great because it handles internationalization right out of the box. I often use this in applications that need to support users from different regions.

You can see the output in the screenshot below; this is so powerful.

TypeScript get current date

Performance Considerations

When working on high-performance applications, date handling can sometimes impact performance. Here are my recommendations:

  1. Native Date object: Fastest for simple operations but lacks formatting options
  2. date-fns: Good balance of performance and features
  3. Intl.DateTimeFormat: Excellent for internationalization with acceptable performance
  4. moment.js: Consider alternatives for new projects due to size and performance concerns

In a recent project for a US client tracking real-time stock transactions, we needed to display timestamps in US Eastern Time. I used date-fns with time zone support:

import { format, utcToZonedTime } from 'date-fns-tz';

// Get current date in US Eastern Time
const estTimeZone = 'America/New_York';
const currentDateEST = utcToZonedTime(new Date(), estTimeZone);

// Format date for displaying transaction timestamps
const timestamp = format(currentDateEST, 'MMM d, yyyy h:mm:ss a zzz', { timeZone: estTimeZone });
console.log(timestamp); // Apr 24, 2025 10:45:23 AM EST

Working with dates in TypeScript doesn’t have to be complicated. For most projects, I recommend using the native Date object for simple cases and date-fns for anything more complex. If internationalization is important, leverage Intl.DateTimeFormat.

I hope you found this guide helpful! If you have any questions or suggestions about working with dates in TypeScript, feel free to share them in the comments below.

Other TypeScript tutorials you may also like:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.