| 12345678910111213141516171819202122232425262728293031 |
- import { Component, ViewEncapsulation } from '@angular/core';
- import { DatePipe } from '@angular/common';
- @Component({
- standalone: true,
- selector: 'app-historical-data',
- styleUrls: ['./historical-data.css'],
- imports: [DatePipe],
- templateUrl: './historical-data.component.html',
- encapsulation: ViewEncapsulation.None
- })
- export class HistoricalDataComponent {
- // 在组件类中
- currentDate: string;
- constructor() {
- const now = new Date();
- this.currentDate = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
- }
- currentTime: Date = new Date();
- ngOnInit(): void {
- // 更新时间,每秒更新一次
- setInterval(() => {
- this.currentTime = new Date();
- }, 1000);
- }
- }
|