robisim74 / angular-l10n

Angular library to translate texts, dates and numbers
MIT License
380 stars 59 forks source link

How to display full name of the date? #318

Closed ihor-zinchenko closed 3 years ago

ihor-zinchenko commented 3 years ago

{{ TIMESTAMP | l10nDate:locale.language:{dateStyle: 'medium'} }} I need to display in first case only day of the week, for example Mondey

What the correct way to do this?

robisim74 commented 3 years ago

@ihor-zinchenko as custom options, you can pass Intl.DateTimeFormatOptions (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat), like this:

<p>{{ today | l10nDate:locale.language:{ weekday: 'long' } }}</p>

ihor-zinchenko commented 3 years ago

@robisim74 hi! thanks) tell me please what the correct way to display numbers instead string

{{ today | l10nDate:locale.language:{ weekday: 'number' } }}

- for example 02 / 03 / 04
robisim74 commented 3 years ago

From the link above:

weekday
The representation of the weekday. Possible values are:
"long" (e.g., Thursday)
"short" (e.g., Thu)
"narrow" (e.g., T). Two weekdays may have the same narrow style for some locales (e.g. Tuesday's narrow style is also T).

If you need only the weekday number, you can just use JavaScript:

var day = new Date().getDay(); // Number from 0 to 6 (0=Sunday 1=Monday 2=Tuesday ...)

ihor-zinchenko commented 3 years ago

ok thanks!)

ihor-zinchenko commented 2 years ago

@robisim74 hi, could you please help me a bit? how i can display date like that: Mar 10, 2022 02:03 i tried:

{{ date | l10nDate:locale.language:{ month: 'short', day: '2-digit', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: false  } }}

but i've got Mar 10, 2022, 02:03 and i have no idea how to remove , symbol

robisim74 commented 2 years ago

I think the simplest method is the joining of the two parts:

{{ date | l10nDate:locale.language:{ month: 'short', day: '2-digit', year: 'numeric' } }}&nbsp;{{ date | l10nDate:locale.language:{ hour: 'numeric', minute: 'numeric', hour12: false } }}