ItSolutionStuff.com

Angular Get Current Date and Time Example

By Hardik Savani • May 2, 2024
Angular

Hi,

I am going to explain you example of angular get current date and time. i would like to show you how to get current date and time in angular. this example will help you how to get current date in angular 12. In this article, we will implement a get current time in angular. Let's get started with get current date in angular.

We can get current date and time in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17.

In this example we will use Date class and DatePipe for getting current date and time in angular app.

Let's see bellow example code here:

src/app/app.module.ts

import { NgModule } from '@angular/core';

import { BrowserModule } from '@angular/platform-browser';

import { FormsModule } from '@angular/forms';

import { DatePipe } from '@angular/common';

import { AppComponent } from './app.component';

@NgModule({

imports: [BrowserModule, FormsModule],

declarations: [AppComponent],

providers: [DatePipe],

bootstrap: [AppComponent],

})

export class AppModule {}

src/app/app.component.ts

import { Component, VERSION } from '@angular/core';

import { DatePipe } from '@angular/common';

@Component({

selector: 'my-app',

templateUrl: './app.component.html',

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular ' + VERSION.major;

constructor(public datepipe: DatePipe){

let currentDateTime =this.datepipe.transform((new Date), 'MM/dd/yyyy h:mm:ss');

console.log(currentDateTime);

}

}

Output:

10/21/2021 9:38:59

I hope it can help you...

Tags: Angular
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular Material Multi Select Dropdown Example

Read Now →

Angular Image Upload with Progress Bar Example

Read Now →

Angular Ngclass with Ternary Operator Example

Read Now →

Angular 12 Routing Tutorial Example

Read Now →

Multiple File Upload in Angular 12 Example

Read Now →

Angular Convert HTML to PDF File Example

Read Now →

Angular Google Maps with Places Search Example

Read Now →

How to use Bootstrap Datepicker in Angular?

Read Now →

Angular 8 Multiple File Upload Example

Read Now →

How to Redirect to Another Page in Angular?

Read Now →

How to Get Current URL in Angular?

Read Now →