Setting moment value to specific time zone directly

Discussão em 'Angular' iniciado por MB34, Outubro 23, 2024.

  1. MB34

    MB34 Guest

    We are using Moment v2.30.1. We are attempting to apply a StartDateTime to an object but it is always being set to utc(). We want to set it directly to the America/Chicago time zone.

    Here is the object with the startDateTime value:

    export interface ExPCReq extends BaseModel {
    description: string | null | undefined;
    action: PA;
    startDateTime?: moment.Moment;
    userId: number;
    }


    This is how it currently is being set:

    const pCReq: ExPCReq = {
    description: this.paFrmGrp.get('descriptionCtrl')?.value as string,
    action: PA.Move,
    startDateTime: moment.utc(),
    userId: this.userService.userDetails.value.userId
    };


    I've tried a lot of things but this sets it to a null value because it says that it is an invald date because it's trying to set the value as a string, correct?

    const pCReq: ExPCReq = {
    description: this.paFrmGrp.get('descriptionCtrl')?.value as string,
    action: PA.Move,
    startDateTime: moment.tz(moment.toString(), "MM/DD/YYYY h:mm a", "America/Chicago"),
    userId: this.userService.userDetails.value.userId
    };


    When I inspect the startDateTime value, isUTC is always set to true, even in the second case above.

    I'm just a little confused with this Moment library. It used to be a lot simpler as I used it about 10-12 yrs ago.

    Continue reading...

Compartilhe esta Página