Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

mat datepicker timezone not correct

import { Inject, Injectable, Optional } from '@angular/core';
import { MAT_DATE_LOCALE } from '@angular/material';   
import { MomentDateAdapter } from '@angular/material-moment-adapter';
import { Moment } from 'moment';
import * as moment from 'moment';

@Injectable()
export class MomentUtcDateAdapter extends MomentDateAdapter {

  constructor(@Optional() @Inject(MAT_DATE_LOCALE) dateLocale: string) {
    super(dateLocale);
  }

  createDate(year: number, month: number, date: number): Moment {
    // Moment.js will create an invalid date if any of the components are out of bounds, but we
    // explicitly check each case so we can throw more descriptive errors.
    if (month < 0 || month > 11) {
      throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
    }

    if (date < 1) {
      throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
    }

    let result = moment.utc({ year, month, date }).locale(this.locale);

    // If the result isn't valid, the date must have been out of bounds for this month.
    if (!result.isValid()) {
      throw Error(`Invalid date "${date}" for month with index "${month}".`);
    }

    return result;
  }
}
Comment

mat datepicker timezone not correct

providers: [
    ...
    { provide: MAT_DATE_LOCALE, useValue: 'en-GB' },
    { provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS },
    { provide: DateAdapter, useClass: MomentUtcDateAdapter },
    ...
],
Comment

PREVIOUS NEXT
Code Example
Typescript :: return n elements from list java 
Typescript :: <edit-config changes in this plugin conflicts with <edit-config changes in config.xml. Conflicts must be resolved before plugin can be added 
Typescript :: tsconfig.json, Typescript 
Typescript :: split dict into multiple dicts python 
Typescript :: TypeError: key must be an instance of a class implements jwt.AbstractJWKBase 
Typescript :: typescript reduce filter examples 
Typescript :: ts new example 
Typescript :: text size in plots in r 
Typescript :: +github graphql api get commits from repo 
Typescript :: paragraph dots after 2 lines css 
Typescript :: listen to server sent events flutter 
Typescript :: download toasts in django 
Typescript :: regex exec returns null 
Typescript :: jest not toBe 
Typescript :: nest js http exceptions 
Typescript :: indexof typescript 
Typescript :: typescript class example 
Typescript :: typeorm configuration typescript 
Typescript :: can you make twitter bots in node.js 
Typescript :: babel typescript 
Typescript :: minuts bwtewwn two date laravel 
Typescript :: string to int tsx 
Typescript :: multicolor points in one legend entry python 
Typescript :: ngx-numeral 
Typescript :: how to make a class that inherits from another file class in python 
Typescript :: python double check if wants to execute funtion 
Typescript :: scss all elements inside 
Typescript :: ruby all elements in array are equal 
Typescript :: enum to number typescript 
Typescript :: 1st heghts value in sql 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =