Angular format date not rendering - angularjs

I'm trying to use Angular's date/time formatting with this string
2015-01-20 16:49:07+00:00
{{ myDate | date : 'medium' }}
However, it doesn't seem to be working? Is the original string messed up?

According to the angular date filter docs:
Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.
You'll notice that for an ISO 8601 date, you need a T before the time:
"2015-01-20T16:49:07+00:00"
http://jsfiddle.net/p84zjy6t/

The correct usage is:
{{ date_expression | date : format }}
To check all format options check the docs

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.

Date time not formating in AngularJs 1.6

I've got this format of date coming from an api:
"dateTime": "2018-02-19 00:00:00.000-08:00"
I just want the days, month and year in the format: dd/MM/yyyy
I'm using this in the view:
<td>{{dado.dateTime | date:'dd/MM/yyyy'}}</td>
But it's shows the date extacly as it comes from the API. Without any formatting
OBS: Angular 1.6
You are missing the T in your original DateTime. For ISO8601 DateTime it should be "2018-02-19T00:00:00.000-08:00" as the value. That is what can be translated by the angular date filter as a DateTime, currently it can only be interpreted as a string.
From the documentation on the input:
Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.
If you do not have any control over the server/source then you have a couple of options:
Change the value of the date time string in the factory/service when you receive the data so it is ISO8601 compliant. This can be as simple as using a regex or string concatenation as long as the T character is added between the date and time. In this specific case you could take the first 10 characters as you probably want to completely ignore the time portion but that would not work where you do want to show or keep time as a part of the datetime.
Create your own filter that then calls through to the built in date filter once you format the input correctly.

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.

SQLite: Extract time from string using strftime

I have database column with time (string is used as data type of the column) in this format '30.09.2014 09:03:01'. I'd like to get timestamp from that column using:
SELECT id, strftime('%d.%m.%Y %H:%M:%S', date) AS time FROM table;
But I get empty column with time. I think there is a problem with dots as a separators. Can anyone help me with that?
The strftime format string is used to specify the output format for printing a date that is supplied in one of the standard formats. The input formats accepted are one of the following:
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
DDDDDDDDDD
You may need to do some string manipulation to reformat the date strings into a format that sqlite can interpret. Often it is convenient to reformat the date when inserting the data initially.
Reference sqlite documentation.

Angular js Date Formatting

I want to change the date format from 10/07/2015(mm/dd/yyyy) to oct 7 ,2015 in angular js
i'm using {{'10/07/2015' | date:'longDate'}} and is giving me the same date '10/07/2015' as output
can any one help me with this?
As per the documentation, you have to format your date in a specific way for the date filter to work properly:
Documentation:
Date to format either as Date object, milliseconds (string or number) or various >ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter >versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone >is specified in the string input, the time is considered to be in the local >timezone.
Example ISO formatted:
<div>{{ "2015-10-07" | date:'longDate' }}</div>
Fiddle

Resources