Time shown incorrectly from Angular - angularjs

Usually code like as:
html
<p class="small-grey-text float-left">
{{ product.date-created | date:'MMMM dd, yyyy ' }}
</p>
json
[{"date-created": 1475798400 }]
This is must look as October 07, 2016
Result
January 01, 1970

It looks like you are having the same problem as in this thread. The date pipe format is correct you need to multiply out the date by 1000.

date-created or dateCreated is word of element for JS.
Let me that is like with working - date_created or datecreated

Related

angular date format gotcha

I don't understand what is happening with date in angular world
I have create same date and trying to display them in local or UTC but getting unexpected result
UPDATE:
I want to know are the actual value and display value same in following cases?
why adding timezoe to date filter does not do anything?
if I want to create date and set hour to 12 PM UTC and to be display locally what is the correct way.
is it possible to create an specific date with hour set 12 in UTC and always display in UTC (not local timezone)
//template
<div ng-app ng-controller="MyCtrl">
<p>expecting date in local time {{date1}} </p>
<p>expecting date in local time along with time offset{{date1 | date:'yyyy-MM-dd hh:mm a Z' }} </p>
<p>expecting date in UTC time along with time offset{{date1 | date:'yyyy-MM-dd hh:mm a Z': 'UTC'}}</p>
<p>expecting date in local time {{date1 | date:'yyyy-MM-dd hh:mm a': 'UTC'}}</p>
<p>expecting time to be -10 hour from UTC {{date1 | date:'yyyy-MM-dd hh:mm a ': '-1000'}}</p>
<p>Expecting it to be in UTC: {{date2}}</p>
<p>Expecting it to be in UTC same as above {{date2 | date:'yyyy-MM-dd hh:mm a': 'UTC'}}</p>
<p>Expecting it to be -10 from UTC {{date2 | date:'yyyy-MM-dd hh:mm a': '-1000'}}</p>
<p>expecting it to be +12 from utc {{date4 |date:'yyyy-MM-dd hh:mm a': 'UTC'}}</p>
</div>
and following is my controller
// controller
function MyCtrl($scope, $filter) {
$scope.date1 = new Date("2017-12-13");
$scope.date2 = new Date(2017,11,13).toISOString();
$scope.date3 = new Date(2017,11,13);
$scope.date4= new Date($scope.date2).setHours(12)
console.log('date1',$scope.date1);
console.log('date2', $scope.date2);
console.log('date3', $scope.date3);
console.log('date4', $scope.date4);
console.log($filter('date')($scope.date2, 'medium'));
}
[Fiddle][1]
[1]: https://jsfiddle.net/sohail85/bzwoxtw2/

angular date filter no effects

I have date in this format
2016-05-22 08:00:00
I am trying to apply a filter like this
<td>{{ event._source.event_date | date : "dd.MM.y"}}</td>
but this does notthing.
What am I missing?
The date pipe requires the value of type Date. A value of string is currently not supported (but work-in-progress).
You can convert the date using new Date('2016-05-22 08:0:00') (not checked if the format is correct and accepted though)
Angular 1:
Add following function to your scope to get Date object from your string. First it converts your string with date to format YYYY-MM-DDTHH:MM:SS (adding 'T' between YYYY-MM-DD and HH:MM:SS).
$scope.isoDate = function(dateString) {
return new Date(dateString.split(' ').join('T'));
};
Now you can use it:
{{ isoDate(event._source.event_date) | date : "dd.MM.y" }}
See jsfiddle

Angular date filter not working

Not working or I'm not using it correctly. I have a date saved in mongodb (which is correct) as:
"2015-12-10T12:00:00.000Z"
I have an angular filter of date as:
date: 'medium' that shows Dec 10, 2015 7:00:00 AM in the view
date: 'medium' : +0500 bumpeds it to Dec 10, 2015 5:00:00 PM
date: 'medium' : -0500 it shows as: Dec 10, 2015 7:00:00 AM AGAIN
How the hell do I get it to show at 12pm?! lol I'm on EST time
The Z at the end means "UTC". So, that date represents the instant that is displayed as 2015-12-10T12:00:00.000 in the UTC time zone.
And you want to display it as if you were in the UTC time zone, since you don't want the time part to be different from the one it has in UTC.
So, use UTC as the time zone:
date:'medium':'UTC'
Output:
Dec 10, 2015 12:00:00 PM
filter
Create a custom filter first:
.filter( 'trimDateTime', function(){
function(ds){
var z = ds.indexOf('Z')
return ds.substr(0, z)
}
}
html
Then apply 2 filters to the data
<p>{{ dateString | trimDateTime | date: 'medium' }}</p>
why
Angular filters are powerful mechanisms for leaving your data intact but rendering a special way. You could have easily trimmed the 'Z' from your date string but then later on, another UX might be expecting that data to be intact.
codepen
http://codepen.io/jusopi/pen/pgvOBr

AngularJS : display epoch in pst/pdt using date filter

I am getting date in epoch format from the backend.
updatedOn = 1427171737000 (from backend)
I am using angular filter to display the date.
{{updatedOn | date: "MM/dd/yyyy ' ' h:mma Z" }} ==> it turns to be 2015-03-23 21:35:37 -0700
I would like my output to be displayed in PST format which will be 2015-03-24 04:35:37
Any ideas?
If you are using 1.3+ of AngularJS then you just need to pass in the timezone
{{ date_expression | date : format : timezone}}
https://code.angularjs.org/1.3.15/docs/api/ng/filter/date if you want to read further.
{{updatedOn | date: "MM/dd/yyyy" : 'PST' }}

Get month from datefield

I using Django-rest and I want to get month form Datefield in AngularJS.
My code is date = '2014-2-30' and I get month: var x = (new Date (Date.parse (date).getMonth().
But x = 1 and value of year = 114.
I read https://docs.angularjs.org/api/ng/filter/date but I can't do it. Would you give me example?
Django REST Framework should pass dates back to Angular in ISO 8601 format (yyyy-MM-dd), so there shouldn't be an issue parsing it on Angular's side.
{{ obj.date | date:"MMMM" }}
MMMM is the Angular date code for the full month (January-December). You can find other Angular date codes in the date filter documentation.

Resources