Choose datetime datepicker formatting in ng-pick

Currently, I am utilizing Angular and have incorporated the ng-pick-datetime npm. However, when attempting to adjust the format after selecting a date (dd/MM/yyyy), it consistently displays as (MM/dd/yyyy) instead. I am uncertain about how to rectify this situation.

To provide further clarity on my issue, refer to the screenshot below:

https://i.stack.imgur.com/zP3dK.jpg

HTML

<input
    [owlDateTime]="dt1"
    [owlDateTimeTrigger]="dt1"
    placeholder="Wedding Anniversary"
    formControlName="wedding"
    class="form-control"
    onkeydown="return false"
    id="text-input"
    name="wedding"
    max="{{ maxDate | date: 'yyyy-MM-dd' }}"
  />
  <owl-date-time #dt1 [pickerType]="'calendar'"></owl-date-time>

I am seeking to achieve the desired result of (dd/MM/yyyy). Thanks in advance for any assistance provided...

Answer №1

Integrate an object into your component that includes the desired date format.

For more details:

import { DateTimeAdapter, OWL_DATE_TIME_FORMATS, OWL_DATE_TIME_LOCALE } from 'ng-pick-datetime';
import { MomentDateTimeAdapter } from 'ng-pick-datetime-moment';

export const MY_CUSTOM_FORMATS = {
  parseInput: 'DD/MM/YYYY',
  fullPickerInput: 'DD/MM/YYYY hh:mm a',
  datePickerInput: 'DD/MM/YYYY',
  timePickerInput: 'hh:mm a',
  monthYearLabel: 'MMM-YYYY',
  dateA11yLabel: 'LL',
  monthYearA11yLabel: 'MMMM-YYYY'
};

@Component({
  selector: 'time-series',
  templateUrl: './time-series.component.html',
  styleUrls: ['./time-series.component.scss'],
  providers: [
    { provide: DateTimeAdapter, useClass: MomentDateTimeAdapter, deps: [OWL_DATE_TIME_LOCALE] },
    { provide: OWL_DATE_TIME_FORMATS, useValue: MY_CUSTOM_FORMATS }
  ]
})
@Injectable()
export class TimeSeriesComponent {
   ....
}

Answer №2

Utilizing picker with MomentJS Below is a demonstration of utilizing OwlMomentDateTimeModule with various date-time formats: (Please note that OwlMomentDateTimeModule relies on MomentJS)

Installation via npm:

npm install ng-pick-datetime-moment moment --save;

Example Code:

import { NgModule } from '@angular/core';
import { OwlDateTimeModule, OWL_DATE_TIME_FORMATS} from 'ng-pick-datetime';
import { OwlMomentDateTimeModule } from 'ng-pick-datetime-moment';

// Refer to the Moment.js documentation for the explanation of these formats:
// https://momentjs.com/docs/#/displaying/format/
export const MY_MOMENT_FORMATS = {
    parseInput: 'l LT',
    fullPickerInput: 'l LT',
    datePickerInput: 'l',
    timePickerInput: 'LT',
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM YYYY',
};

@NgModule({
    imports: [OwlDateTimeModule, OwlMomentDateTimeModule],
    providers: [
        {provide: OWL_DATE_TIME_FORMATS, useValue: MY_MOMENT_FORMATS},
    ],
})
export class AppDemoModule {
}

Answer №3

Currently, everything is functioning perfectly for me after reading the documentation. Insert the following code snippet into the module:

providers: [
    ClientService,
    DatePipe, 
    {provide: OWL_DATE_TIME_LOCALE, useValue: 'in'}
]

Answer №4

make changes in the app.module file

providers:[
{provide: DATE_TIME_LOCALE, useValue: 'en-GB'}
]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on implementing ng-if in an Ionic 2 HTML template

To display records if found and show "no records found" otherwise, I have implemented the code below: <div ng-if="program.videourl"> <video width="100%" controls="controls" preload="metadata" webkit-playsinline="webkit-playsinline" class="vide ...

Creating a personalized NPM package: Converting and exporting TypeScript definitions

Question: Do I need to adjust my TS configuration or add a TS build step? I recently developed a new npm package: Custom-NPM-Package / - src -- index.js -- index.d.ts -- IType.ts accompanied by this tsconfig.json: { "compilerOptions" ...

Guide on saving a PDF file after receiving a binary response using axios

Is there a way to save a PDF file from a binary response received through an axios get request? When making the request, I include the following headers: const config: AxiosRequestConfig = { headers: { Accept: 'application/pdf', respon ...

Exploring the Module System of TypeScript

I am working with a TypeScript module structured like this: let function test(){ //... } export default test; My goal is for tsc to compile it in the following way: let function test(){ //... } module.exports = test; However, upon compilation, ...

How can I call a global function in Angular 8?

Currently implementing Angular 8, my objective is to utilize downloaded SVG icons through a .js library. To achieve this, I have made the necessary additions to my .angular.json file: "scripts": [ "node_modules/csspatternlibrary3/js/site ...

Cannot find property '' within type 'never'. (Using TypeScript useState with mapped JSON data from a server)

Currently, I am following a tutorial on using React with Material-UI and decided to add TypeScript into the mix. If you're interested, here is the link: Net ninja MUI The file Notes.tsx contains the code for fetching data from a JSON server and then ...

I am currently working to resolve this particular wildcard issue with the help of TypeScript

I've been working on solving the wildcard problem with TypeScript, but I'm running into issues with some of the test cases I've created. Here's a brief overview of how the code operates: A balanced string is one where each character ap ...

What is the best way to retrieve the parameter of ng2-file-upload using endback?

I am attempting to retrieve a parameter using PHP in order to save it into a folder. However, my code is not working as expected. Here is the code snippet: Using the Ionic framework this.uploader.onBeforeUploadItem = (item: any) => { this.uploader ...

Encountering a problem while trying to start a create-react-app using npm

Currently delving into React and here's what I've accomplished so far: npm i -g create-react-app (completed successfully) create-react-app react-app (completed successfully) cd react-app npm start (encountered an error above) Here's the o ...

Whenever I attempt to run `npm install`, I encounter the frustrating error message "access denied."

I'm facing an issue while installing a new project, and I keep getting the error message shown below after running npm install. I've already attempted a solution provided here, but it didn't work. Running the suggested commands in the termin ...

What causes this conditional type to function correctly in a static context while failing in a dynamic setting

I have created a unique conditional type that accurately generates a union of valid array indices: type ArrayIndices< N extends any[], Acc extends number[] = [] > = Acc['length'] extends N['length'] ? Acc[number] : ArrayIn ...

Error: The argument begins with a non-ASCII dash, suggesting it is likely invalid: [ '- g', 'appium' ]

Whenever I attempt to Install Appium, I am instructed to open Command Prompt or Terminal and enter the following command: npm install –g appium Error Encountered: npm ERR! arg Argument starts with non-ascii dash, this is probably invalid: [ '- g& ...

The Jest test encounters a SyntaxError due to an unexpected token Export causing it to fail

I am encountering an issue where my test is failing with the error message Unexpected token 'export' that stems from code imported from the swiper package. I have attempted to solve this by adding node_modules to the transformIgnorePatterns in my ...

How can I populate an array using values from a different array in Angular?

I am facing an issue with populating three other arrays based on the property 'game type' from my array called 'my games'. Here is an example of the structure of the 'my games' array: hideScore: true, started: true, startedAt: ...

Encountering an Angular schematics issue while utilizing an external schematic ng-new, the specified version is

Attempting to develop a schematic that utilizes the angular ng-new as the initial call and another schematic to add a prettier file to the new project. Upon executing the command, an error is encountered: Data path "" must have required property 've ...

Uh-oh! Looks like we hit a roadblock - npm encountered an error due to exceeding the

I've been struggling with this issue for the past day. I'm attempting to set up webpack using npm by running the following command: $ npm install webpack webpack-cli --save-dev Unfortunately, it's been a complete disaster. I've trie ...

Exploring the process of iterating over asynchronous data in Angular

There is an angular component in my project that fetches data from the server, processes it, and then assigns it to a variable: class Component { data = []; ngOnInit() { this.store.select(data).pipe( map(data => { this.data = this.transf ...

Navigating nested data structures in reactive forms

When performing a POST request, we often create something similar to: const userData = this.userForm.value; Imagine you have the following template: <input type="text" id="userName" formControlName="userName"> <input type="email" id="userEmail" ...

It is not possible to utilize a JavaScript function once the script has been loaded through

I am attempting to programmatically load a local JavaScript file - PapaParse library, and then utilize one of its functions: $.getScript("./Content/Scripts/papaparse.js", function () { console.log("Papaparse loaded successfully"); Papa.parse(file, ...