我只想从1970-01-01T09:30:00.000Z获得时间。例如9.30或16:00。该怎么做?
答案 0 :(得分:1)
您可以使用JavaScript的Date
类。这是一个简短的示例:
const d = new Date('1970-01-01T09:30:00.000Z') // Parses a ISO 8601 Date
console.log(d.getHours()); // gets the hours in the timezone of the browser.
console.log(d.getUTCHours()); // gets the hours in UTC timezone.
console.log(d.getMinutes()); // gets the minutes in the timezone of the browser.
console.log(d.getUTCMinutes()); // gets the minutes in UTC timezone.
console.log(d.getHours() + ':' + d.getMinutes());
console.log(d.getUTCHours() + ':' + d.getUTCMinutes());
答案 1 :(得分:0)
我希望这会在将来对任何人有所帮助。 我认为您可以按如下所示的角度使用Date管道
// React expect no whitespace between table elements
sliced = sliced.replace(/<table>\s*<thead>/g, "<table><thead>");
sliced = sliced.replace(/<table>\s*<tbody>/g, "<table><tbody>");
sliced = sliced.replace(/<thead>\s*<tr>/g, "<thead><tr>");
sliced = sliced.replace(/<tbody>\s*<tr>/g, "<tbody><tr>");
sliced = sliced.replace(/<tr>\s*<th>/g, "<tr><th>");
sliced = sliced.replace(/<tr>\s*<td>/g, "<tr><td>");
sliced = sliced.replace(/<\/thead>\s*<tbody>/g, "</thead><tbody>");
sliced = sliced.replace(/<\/thead>\s*<\/table>/g, "</thead></table>");
sliced = sliced.replace(/<\/tbody>\s*<\/table>/g, "</tbody></table>");
sliced = sliced.replace(/<\/tr>\s*<\/thead>/g, "</tr></thead>");
sliced = sliced.replace(/<\/tr>\s*<\/tbody>/g, "</tr></tbody>");
sliced = sliced.replace(/<\/th>\s*<\/tr>/g, "</th></tr>");
sliced = sliced.replace(/<\/td>\s*<\/tr>/g, "</td></tr>");
sliced = sliced.replace(/<\/tr>\s*<tr>/g, "</tr><tr>");
sliced = sliced.replace(/<\/th>\s*<th>/g, "</th><th>");
sliced = sliced.replace(/<\/td>\s*<td>/g, "</td><td>");
它将给出以下o / p 27/06/2019 01:01:00
仅在以下时间使用
{{ 2019-06-26T19:31:00.000Z | date:"dd/MM/yyyy HH:mm:ss"}}
它将给出以下o / p 01:01
答案 2 :(得分:-1)
MomentJS是一个很棒的JS项目时间管理库,Check it out !
答案 3 :(得分:-1)
您可以像这样使用momentjs:
let YourDate = '1970-01-01T09:30:00.000Z'
let time= moment(YourDate).format("hh:mm a")
以下是一个有帮助的stackbliz网址:
https://stackblitz.com/edit/angular4-momentjs-format-datetime-5etqib?file=app/app.component.ts
答案 4 :(得分:-2)
您可以使用:
date = new Date('1970-01-01T09:30:00.000Z');
// and after this target by:
date.getFullYear()
date.getMonth()
date.getDate();
和其他需要的参数。