تعيين التاريخ والوقت

 المراجع:
https://www.npmjs.com/package/@angular-material-components/datetime-picker

https://bbbootstrap.com/snippets/default-datepicker-16487400



https://bbbootstrap.com/snippets/basic-clockpicker-81609682



إضافة يوم أو سنة على التاريخ:
https://g.co/gemini/share/826be0e8998a

  addOneDay(date: any): Date {
    const newDate = new Date(date.getTime()); // Clone the date object
    newDate.setDate(newDate.getDate() - 1);
    return newDate;
  }

  async findCurrentPromotions():
    Promise<PromotionsMagazine[]> {
    const currentDate = new Date();
    const plusOneDay = new Date(); // Clone the date object
    plusOneDay.setDate(plusOneDay.getDate() + 1);
    // const twoYearsLater = new Date();
    // twoYearsLater.setDate(twoYearsLater.getFullYear() + 2);
    return this.promotionsMagazineRepository.find({
      where: {
        status: 'POSTED',
        show: true,
        // dateStart: LessThanOrEqual(currentDate),
        // expire_date: Between(currentDate, twoYearsLater),
        expire_date: MoreThanOrEqual(this.addOneDay(currentDate))
      },
      order: { id: "DESC" },
    });
  }


أفضل طريقة لتنسيق الوقت:

import { Component } from '@angular/core';
import { formatDate } from '@angular/common';

@Component({
selector: 'app-my-component',
templateUrl: './my-component.html',
styleUrls: ['./my-component.html']
})
export class MyComponent {
myDate = new Date(); // Or any valid Date object

formattedDate = formatDate(this.myDate, 'yyyy-MM-dd', 'en-US'); // Format as YYYY-MM-DD in US English

// Other potential formats:
// - 'shortDate' (e.g., 1/2/2024)
// - 'mediumDate' (e.g., Jan 2, 2024)
// - 'longDate' (e.g., January 2, 2024)
// - 'fullDate' (e.g., Tuesday, January 2, 2024)
}


إجراء حدث أثناء اختيار تاريخ في المجال:

                <div class="col-12 col-md-6 mt-2">
                    <mat-form-field class="w-100" [appearance]="'outline'">
                        <mat-label>{{'LABELS.PROMOTION_PERIOD' | translate}}</mat-label>
                        <mat-date-range-input [rangePicker]="campaignOnePicker" [comparisonStart]="data.start_date"
                            [comparisonEnd]="data.expire_date">
                            <input #_start_date matStartDate [placeholder]="'LABELS.START_OF_PROMOTIONS' | translate"
                            (dateChange)="convertGregorianToHijri(_start_date.value)"
                                [(ngModel)]="data.start_date" formControlName="start_date">
                            <input #_end_date matEndDate [placeholder]="'LABELS.END_OF_PROMOTIONS' | translate"
                            (dateChange)="convertGregorianToHijriForEnd(_end_date.value)"
                                [(ngModel)]="data.expire_date" formControlName="expire_date">
                        </mat-date-range-input>
                        <mat-hint>MM/DD/YYYY – MM/DD/YYYY</mat-hint>
                        <mat-datepicker-toggle matIconSuffix [for]="campaignOnePicker"></mat-datepicker-toggle>
                        <mat-date-range-picker #campaignOnePicker></mat-date-range-picker>
                    </mat-form-field>
                </div>

المصدر:

https://g.co/gemini/share/32bbfbfbe96e















تعليقات

المشاركات الشائعة من هذه المدونة

ngx-extended-pdf-viewer

how to getting access token for https://fcm.googleapis.com/v1/projects/al-ayahya-co/messages:send for angular and backend nestjs

طريقة تفعيل زر Inline Keyboard في Telegram Bot