Date Parsing with Timezone AngularJS - angularjs

In have this line in my code.
<span> {{messages.created_time}}</span>
This is the ouput
2017-04-29T12:46:49+0000
However, I would like the ouput to be :
n minutes ago // if less than one hour following the user timezone
22:46 // if more or equal than one hour following the user timezone
SUN AT 22:46 // if more or equal than a day following the user timezone
APRIL 2 AT 22:46 // if more or equal than a week following the user timezone
I am using angular js.
Thanks

This should be simply done by using moment.js. Just use angular filter and apply your custom logic.
<span> {{messages.created_time | filterfn}}</span>
function filterfn(time){
// all custom logic for span text creation
return $moment(time);
}

Related

How do I calculate age from a given date of birth in ExtJS Framework?

Am trying to calculate age from a given date of birth in extjs, Anyone one can help?
I tried creating a function but it never worked for me
The method Ext.Date.diff should solve this problem.
In your case the first param should be your "birthday" and the second value the current date. As unit you want the year.
Here is working code:
Ext.Date.diff(new Date('10-20-2000'), new Date(), 'y')
This should return the number 22. So your Age would be 22.
Here is a working example to show this example in an extjs form: sencha fiddle

React-Moment- Parsing ISO 8601 Time Left Into Readable Format

I'm trying to take the 'timeLeft field from the eBay API and turn it into something that looks normal, like 3 Hours, 10 Minute and 5 seconds left.
The data looks something like this: P3DT6H28M15S
I'm trying to use the React Moment module but can't figure out exactly how to do this.
This is my latest test:
<Moment format="h:mm:ss">
{card.sellingStatus && card.sellingStatus[0].timeLeft}
</Moment>
But this is returning 'invalid date'.
I also try the following code just to see what HTML output looks like, but i'm trying a different output field
<Moment>{card.listingInfo && card.listingInfo[0].endTime}</Moment>
note that endTime looks like this
2019-11-09T19:45:32.000Z
but the above code is generating the same exact value for each item
Tue Jan 01 2019 00:00:00 GMT-0500
even though all of the endTime fields are different
Any ideas as to what I might be doing wrong here?
So i mostly accomplished what I needed by using the react-timeago npm module.
<TimeAgo
date={new Date(
card.listingInfo && card.listingInfo[0].startTime
).toLocaleDateString()}
/>

Angularjs date pipe filter gives wrong output

Currently I am using angularjs in my project in which i am converting a date format '2019-05-09T20:09:11.677Z' using angular js to 'MM/dd/yyyy' but its giving me wrong output '05/10/2019'. Expected Output is '05/09/2019'.
What is the issue? Can anybody help me.
{{'2019-05-09T20:09:11.677Z' | date:'MM/dd/yyyy'}}
Current Output (Wrong): 05/10/2019
Expected Output (Right) : 05/09/2019
Date filter considers your timezone. Since the date you're trying to print has 8pm as time, I guess you're in a timezone in the range +0400 and +1200, making the date falling into 05/10/2019.
If you want to force the timezone to something different, e.g. UTC, you can use
{{ '2019-05-09T20:09:11.677Z' | date:'MM/dd/yyyy' : '+0000' }}
You have to specify timezone as one of parameters.
{{ date_expression | date : format : timezone}}
eg:
{{date| date:'shortDate':'GMT' }}
For more Information AngularJs
Small demo for your help Demo

Date Comparision in Angularjs ng-if

I am trying to compare two dates Event Date and Current Date.I have two divisions in my HTML page.One is past events in which Event date which has crossed the current date will be automatically placed into Past events div.Another division is Upcoming Events in which event date is greater than current date.
Condition I am using is
<data-ng-if="(event.eventDate | date:'yyyy-dd-MM HH:mm:ss')>
(todayDate | date:'yyyy-dd-MM HH:mm:ss')">
If it is true the added event will be placed into Upcoming events div section.Otherwise,
<data-ng-if="(event.eventDate | date:'yyyy-dd-MM HH:mm:ss')<
(todayDate | date:'yyyy-dd-MM HH:mm:ss')">
Then Added event will be placed into Past events section.
In Controller.js I am writing function
$scope.init = function() {
$scope.todayDate = new Date();
}
But right now it is comparing only the day.For example if today date is 2017-07-27 and if I enter 2017-06-30 while adding events then it should go to Past Events section but it is getting added in Upcoming events section only because it is comparing only day that is 30 and 27 as in the example.And if suppose today date is 2017-07-27 and if i add event date as 2017-08-20 then it should be placed in Upcoming events but it gets added into past section.Can anyone tell me how to achieve this with yyyy-MM-dd HH:MM:SS format?It has to compare time also.
When comparing dates you shouldn't use the string notations. You can just compare the date objects itself:
<data-ng-if="event.eventDate < todayDate">

how to filter date with given timezone in angularjs

this the time format i need to convert with angular, in the format each has its own timezone(at the end starts with +) and i want to filter with related to their timezone.
"2016-09-01T11:15:00.000+01:00"
"2016-09-01T21:50:00.000+03:00"
"2016-09-02T07:30:00.000+05:00"
what i tried to do was returning me my browser timezone:
{{o.ArrivalTime | date:'dd MMMM HH:mm'}}
o.arrivaltime is what that gives me the above time stamp.

Resources