historical-data.component.ts 773 B

12345678910111213141516171819202122232425262728293031
  1. import { Component, ViewEncapsulation } from '@angular/core';
  2. import { DatePipe } from '@angular/common';
  3. @Component({
  4. standalone: true,
  5. selector: 'app-historical-data',
  6. styleUrls: ['./historical-data.css'],
  7. imports: [DatePipe],
  8. templateUrl: './historical-data.component.html',
  9. encapsulation: ViewEncapsulation.None
  10. })
  11. export class HistoricalDataComponent {
  12. // 在组件类中
  13. currentDate: string;
  14. constructor() {
  15. const now = new Date();
  16. this.currentDate = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
  17. }
  18. currentTime: Date = new Date();
  19. ngOnInit(): void {
  20. // 更新时间,每秒更新一次
  21. setInterval(() => {
  22. this.currentTime = new Date();
  23. }, 1000);
  24. }
  25. }