Angular localization problems with number and date format - angularjs

I am trying to format a date based on localisation and have the locale files setup correct so when using date format of shortDate I get the difference between UK and US format.
However we need the date to show the full year 2016 and not 16.
If I code it as dd MM yyyy then that gives me the correct UK format but when toggling to US mode the filter keeps it in that dd MM yyyy format.
How can I enable the date to be of type day month year for UK and month day year for US etc ?

Try https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
// US English uses month-day-year order
console.log(date.toLocaleDateString('en-US'));
// → "12/19/2012"
// British English uses day-month-year order
console.log(date.toLocaleDateString('en-GB'));
// → "20/12/2012"
Note this is not IE friendly like most of html5 and ES6 :v.
other way is to use http://momentjs.com/

Related

angularjs Date Daylightsaving issue

I am using date to display my date on html like:
{{updateDate| date: 'dd/MM/yyyy HH:mm:ss'}}
Dates are all saved in UTC. The problem is it displays the date in locale timezone but not considering Daylight saving on/off. As in for BST it always shows +1 hr from UTC.
I want it to also consider DST(daylight saving time).
Any help, please.
{{ date_expression | date : format : timezone}}
As per angular date filter documentation:
date: Here date can be Date Object, milliseconds or ISO 8601 datetime string formats (like: e.g. yyyy-MM-ddTHH:mm:ss.sssZ). Here Z is 4 digit (+sign) representation of the timezone offset (-1200-+1200). If no timezone is specified in the string input, the time is considered to be in the local timezone.
format: this is optional, If not specified, mediumDate(equivalent to 'MMM d, y' for en_US locale (e.g. Sep 3, 2010)) is used.
timezone: Timezone to be used for formatting. It understands UTC/GMT and the continental US time zone abbreviations, but for general use, use a time zone offset, for example, '+0430' (4 hours, 30 minutes east of the Greenwich meridian) If not specified, the timezone of the browser will be used.
This may help you.

Style each section of a date after it been formatted with the correct date format

My problem is styling a date object properly. I would like to style the day month year and sometimes day of the week. If the date object is static it would be simple. The date format is passed in and usually takes in the account of localization so I don't know what the format will look like. I could be given mm/dd/yyyy or mm/dd/yyyy (Simple case). Currently, we just pass it through angular date filter and it produces the correct date, but I can't style the month to be bold and blue for example.
Is there an easy way to parse a date with the format of dd/mm/yyyy and gives me:"12/12/1988"
Angular ships with a Date filter.
<p>{{'1491941202157' | date:'dd/MM/yyyy'}}</p> => 11/04/2017
Pair that up with a directive using the $filter in the controller, or simply split the string on / and wrap in style-able nodes like <span>, for example.
More here: https://docs.angularjs.org/api/ng/filter/date

AngularJS datetime format get wrong hour and minute value based on localization

I have datetime value on database as follow
But following angularJS code display wrong hour in View
<i title="Baxıldı {{item.ViewedDate | date: 'dd.MM.yyyy hh:mm:ss Z'}}"></i>
for example:
I think this error depends on localization, in my country is UTC+4, so 4 hours added to current value.
Please help to solve this problem.
You can add timezone as the third argument when you're using the date filter.
{{ date_expression | date : format : timezone}}
Here's an example if the dates in your database in stored in UTC.
<i title="Baxıldı {{item.ViewedDate | date: 'dd.MM.yyyy hh:mm:ss Z': 'utc'}}"></i>
From the docs:
Timezone to be used for formatting. It understands UTC/GMT and the
continental US time zone abbreviations, but for general use, use a
time zone offset, for example, '+0430' (4 hours, 30 minutes east of
the Greenwich meridian) If not specified, the timezone of the browser
will be used.

Support dates with optional month and day in angular date input or uib-dateparser

I want to support the dates in the following formats in my angular bootstrap input: YYYY, MM.YYYY and DD.MM.YYYY. At the same time I want to send to the server the dates in the following formats: YYYY, YYYY-MM, YYYY-MM-DD. The user enters the date from the keyboard, no datepicker is needed. Is there an easy way to do that? I saw uib-dateparser, but it seems that it doesn't support optional MM and DD.

What's the meaning 'EEE'

Looking at date filter on angular.js, EEE is used on the spot of the day of the week part, What's the meaning EEE?
The EEE term is used to custom format Datetime String:
'EEEE': Day in Week,(Sunday-Saturday)
'EEE': Day in Week, (Sun-Sat)
reference -> https://docs.angularjs.org/api/ng/filter/date
Usage
In HTML Template Binding:
{{ date_expression | date : format : timezone}}
In JavaScript:
$filter('date')(date, format, timezone)
From: angularjs docs
'EEE': Day in Week, (Sun-Sat)
That is, providing a formatter of 'EEE' will convert the date object to expose only the day in the week (like Sunday).

Resources