Get locale date format pattern

1 Answer 375 Views
Localization
Yuriy Rogach
Top achievements
Rank 1
Iron
Yuriy Rogach asked on 30 Jul 2021, 09:16 AM

Hi,

I'm trying to find a way to get a date format pattern for the current locale.

Using IntlService.splitDateFormat("d") I'm getting the following array:

[
 {type: "year", pattern: "y"},
 {type: "literal", pattern: "-"},
 {type: "month", pattern: "MM"},
 {type: "literal", pattern: "-"},
 {type: "day", pattern: "dd"}
]

However kendo-datepicker displays a different one as a placeholder

 

Is there a way to get exactly the same date pattern as used in kendo-datepicker?

1 Answer, 1 is accepted

Sort by
0
Hetali
Telerik team
answered on 03 Aug 2021, 07:52 PM | edited on 06 Aug 2021, 08:53 PM

Hi Yuriy,

In order to get the date format of the current locale, use the template variable and the ViewChild decorator as seen below:

<kendo-datepicker
  #dateFormat
  [value]="value"
>
</kendo-datepicker>

<button class="k-button" (click)="getFormat()">Get Format</button>
@ViewChild('dateFormat') public dateFormat;

public getFormat() {
  this.format = this.dateFormat.input.currentFormat;
}

In this StackBlitz example, on button click, you can get the current format of the Kendo UI DatePicker based on the locale.


Similarly, to get the placeholder/text of the Kendo UI DatePicker, please make the following changes:

public getFormat() {
  this.format = this.dateFormat.input.currentValue;
}

This StackBlitz example shows the text displayed in the Kendo UI DatePicker which is either a date or a placeholder. 


I hope this helps. Please let me know in case you have any further questions pertaining to this case.

Regards,
Hetali
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Yuriy Rogach
Top achievements
Rank 1
Iron
commented on 06 Aug 2021, 04:05 PM

Hi Hetali,

Thanks for the help. Actually, I'm interested in exactly the same format Kendo UI DatePicker uses for placeholder or rather a text, is there a way to get it?

Hetali
Telerik team
commented on 06 Aug 2021, 09:00 PM

Hi Yuriy,

Please take a look at the updated answer to get the placeholder of the Kendo UI DatePicker. Let me know if the solution helps.

Thanks,
Hetali

Yuriy Rogach
Top achievements
Rank 1
Iron
commented on 09 Aug 2021, 07:44 AM

Hi Heteli,

Thanks, it works well!

Tags
Localization
Asked by
Yuriy Rogach
Top achievements
Rank 1
Iron
Answers by
Hetali
Telerik team
Share this question
or