$scope.articles = [
{
link: "",
source: "Google",
title: "hello",
"date": new Date(2008, 4, 15)
},
];
<tbody>
<tr ng-repeat = "article in articles | orderBy:sortType:sortReverse | filter:searchArticle ">
<td>{{article.source}}</td>
<td><a href="{{article.link}}" target="_blank" rel="noopener noreferrer">{{article.title}}</a></td>
<td class="date-table-td">{{article.date | date:'longDate'}}</td>
</tr>
</tbody><!-- End table body -->
Hi, I currently have this. So the date shows as May 15, 2008. How do I show only the year or only the year+month?
Thanks.
$scope.articles = [
{
link: "http://google.",
source: "Google",
title: "hello",
"date": new Date(2008, 4, 15)
},
];
<tbody>
<tr ng-repeat = "article in articles | orderBy:sortType:sortReverse | filter:searchArticle ">
<td>{{article.source}}</td>
<td><a href="{{article.link}}" target="_blank" rel="noopener noreferrer">{{article.title}}</a></td>
<td class="date-table-td">{{article.date | date:'longDate'}}</td>
</tr>
</tbody><!-- End table body -->
Hi, I currently have this. So the date shows as May 15, 2008. How do I show only the year or only the year+month?
Thanks.
Share Improve this question edited Apr 12, 2018 at 16:04 Jason asked Apr 11, 2018 at 18:46 JasonJason 211 silver badge6 bronze badges 3- 3 Possible duplicate of How to format a JavaScript date – Alexander Lallier Commented Apr 11, 2018 at 18:49
- check Date.prototype – Sphinx Commented Apr 11, 2018 at 18:49
-
2
Actually
new Date(2008, 4, 15)
should show up as May, not March. – kshetline Commented Apr 11, 2018 at 18:50
2 Answers
Reset to default 3According to the documentation, you can use date.getFullYear()
to get the year in YYYY format and date.getMonth()
to get the month.
An example:
let list = document.getElementById('test');
let date = new Date(2008, 4, 15);
// year
let yearNode = document.createElement("li");
yearNode.appendChild(document.createTextNode(date.getFullYear()));
list.appendChild(yearNode)
// year + month
let yearMonthNode = document.createElement("li");
yearMonthNode.appendChild(document.createTextNode(date.getFullYear() + " " + date.getMonth()))
list.appendChild(yearMonthNode)
<ul id="test">
</ul>
with date.getMonth()
you need +1 to this
var month = date.getMonth() + 1
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745121769a4612455.html
评论列表(0条)