is any chance to format date in ng-repeat?
I was trying to format it like
<div class="col-date">{{row.Calendar.start | date : "dd.MM.y"}}</div>
But it was not working. How do I format date in ng-repeat?
Use moment and angular-moment, are definitely best modules out there for stuff related to dates.
First of all convert $scope.row.Calendar.start to date/moment object if it is a string and then use angular moment to show desired date format
Here is a how you can do so:
Inside controller:
$scope.row.Calendar.start = moment($scope.row.Calendar.start,'YYYY-MM-DD HH:mm:ss');
<div class="col-date">{{row.Calendar.start | amDateFormat : "dd.MM.y"}}
From AngularJS perspective everything seems to be valid.
Please check following:
Format of the data you provide to your date filter - is it UNIX timestamp or something else that might be processed by filter?
Check if the data that you are trying to parse, is available
Please provide us with more information about what are you trying to convert, and what result do you have
It seems like you are trying to apply angular date filter of a string object.
Try to first convert it to a Date object in controller and then apply date filter on it.
EXAMPLE
$scope.dtObj = new Date($scope.row.Calendar.start);
then in HTML write this
<div class="col-date">{{dtObj | date : "dd.MM.y"}}</div>
for more details check out documentation here https://docs.angularjs.org/api/ng/filter/date
try this it worked for me hope for you to
{{row.Calendar.start | date:'MMM-dd-yyyy'}}
Related
I'm making an api call which retrieves a set of objects. One of the objects returns a date and time together like this:
createdAt: "2020-11-04 09:48:32"
This is where I display the date and time:
<template v-for="item in collectedTrash">
<BeforeAndAfter v-if="item.isPresented === 1"
:key="item.username"
:avatarUrl="require('#/assets/img/images/img_stats_km#2x.png')"
:imageBefore="getImageUrl(item.imageUrlBefore)"
:imageAfter="getImageUrl(item.imageUrlBefore)"
:username="item.username"
:date="item.createdAt"/> This is where I get the date
</template>
Is there anyway that I can retrieve the date only, rather than the date and time?
I am assuming you don't have access to the api and therefore have to process the date in your vue application.
Do you need the date as a date Object or is a string fine?
If a string representation is enough, you could use a library such as Date fns and use the format function:
...
:date="format(new Date(item.createdAt), 'yyyy-MM-dd')"
Another option might be to only use the first 10 characters of the string you received as the date: date="item.createdAt.substring(0,9)"
Did you try something like: :date="item.createdAt.substr(0, 10)"
In my experience the easiest way to format datetimes in JS it to use the Moment.js library (https://momentjs.com/). You could reformat the datetime string before passing it to your child component.
Or, if you don't want to rely on a third-party library and you know that the datetime string will always be passed in that format, I suppose you could do item.createdAt.slice(0, 10).
Moment.js can be very helpful with dates and times
Moment Docs
moment("String").format('L'); // 04/11/2020
I must be missing something very obvious, but I could use help. I have an Angular web app, which is getting data from a MS Web API. The DTO object has two date fields. When those fields come in, there is a "T" in the date field.
e.g. 2017-05-01T03:43:55
For whatever reason, I can't seem to get rid of that darn "T" when using the date. I'd tried using a date format both on the calendar control that displays the date data, and using the JavaScript format() command. I also tried using the Javascript replace() command to replace the "T" with a space. And I tried using Moment.js to create a new date (which seems to fail and give me an invalid date).
var startDate = moment(badge.startDate).format('yyyy-MM-dd HH:mm:ss');
var startDate = badge.startDate.format(''yyyy-MM-dd HH:mm:ss'');
var startDate = moment(badge.startDate).replace('T',' ');
What am I missing? How should I be doing this? As far as I can tell, any of these should work?
You can create separate filter for that as below.
return (input) ? $filter('date')("2017-05-01T03:43:55", "yyyy-MM-dd HH:mm:ss") : '';
You can change for of date according to your requirements. You can see details Below.
https://docs.angularjs.org/api/ng/filter/date
use, don't build what already exists!
First visit moment js this component is very helpful and has many options which you can do with a date.
var date = moment(yourDate).format('YYYY-MM-DD');
format has a lot of options, you can find it on moment js documents.
Hi I am trying to figure out how to display date properly using angularjs.
My system returns the date in this fromat
c_date="\/Date(1151470800000-0500)\/"
I dont know what format is it.
I am displaying it
using <span>{{pro.c_date | date:'medium')</span>
When i run this i get date printed in same format
"/Date(1151470800000-0500)/"
Can anyone suggest how to fix this so date can be displayed properly.
Thanks
the date that you're trying to use is a invalid date or maybe I don't know what format are the system using.
The problem is that angular.js requires a data object for can format it. Not a date string.
I suppose that the date is 1151470800000 miliseconds since the epoch least 0500 for adjust hours or something.
If this is correct, you only need to make c_date a Date object before pass to view.
c_date = "\/Date(1151470800000-0500)\/";
var the_date = eval("new "+c_date.replace(/\\|\//g, ''));
http://jsbin.com/zuwizoxe/3/
Regards!
I have Date in this format mm/dd/yy example: 04/11/13
and time in the format HH:MM:SS example: 17:02:30
I have to parse above two values and put in a variable dateTime with following format
YYYY-MM-DDTHH:MM:SSS
2013-04-11T17:02:30.000
What is best way to do it in AngularJS or in Javascript. I also need to verify the user input and make sure it is a valid mm/dd/yy date and a valid HH:MM:SS time
I know there are tons of duplicate/similar questions but I couldn't find one which answers above, please let me know if you found one.
You don't need an external library to do this. See this doc link for the forms of date that JavaScript can process normally.
For a specific solution to your question:
var date = new Date("04/11/13" + " " + "17:02:30");
date.toISOString();
>> "2013-04-11T21:02:30.000Z"
See this MDN page for more info on the Date object.
The best way to do this in AngularJS is with a filter. You bind to the dateTime, and then filter it with the date filter.
<span>{{myDate | date:yyyy-MM-ddThh:mm:sss}}</span>
Or in your controller you say:
$filter('date')(date[, format])
Here is more info: http://docs.angularjs.org/api/ng.filter:date
I have an array of
struct {
Date time.Time
PostedSample int
}
loaded from the appengine datastore which I want to output in a html/template for the Google Visualization Time Line. First I tried formatting the Date directly in the template with {{.Date.Format "new Date(2006,1,2,15,4,5)"}} but html/template escapes this so it appears as a quoted string in the html source. I then tried formatting the date into a []struct{Date template.JS; Value template.JS} with the expression template.JS(m.Date.Format("new Date(2006,1,2,15,4,5)")) which almost works except the month is off by one, javascript wants January as 0. I could have the template generate a json of date parameters and write javascript turn that into Date objects or have go code which adjusts the template output. Please share a more elegant solution. Thank you.
You don't need to add a format function to the templates.
You can use your struct like so:
{{.Date.Format "Mon 2 Jan 2006"}}
The solution might be something like this:
var date = new Date(parseInt({{.Date.Nanosecond }} /1000));