当我在控制台中打印我的代码时,我得到的日期和时间与我要求的格式不同
请参阅下面<% if @check %>
if($('.addresses').length) {
$('.addresses').append('<%= j(render('account/addresses/address', address: @address)) %>');
}
if($('#did-addresses').length){
$('#did-addresses').append("<%= "<option selected='true' value='#{@address.id}'>#{@address.name}</option>".html_safe %>").selectpicker('refresh');
}
$('#new-address').html('<%= j(render('account/addresses/form', new_address: @new_address)) %>');
swal({
type: 'success',
title: "<%= t('response.success') %>",
text: "<%= t('flash.actions.create.notice', resource_name: Address.model_name.human) %>",
timer: 2000
});
quickview.close('#new-address');
<% else %>
<% @address.errors.each do |error| %>
<% end %>
<% end %>
$('.preloader').fadeOut();
的代码:
time.ts
我收到以下格式的结果[这是我的控制台窗口中的内容] -
let start = new Date();
console.log(start);
我想要的是 -
2017-01-02 17:15:16
我如何实现这一目标?请帮忙。我只希望Fri Nov 10 2017 16:27:22 GMT+0530 (India Standard Time)
变量的值为start
答案 0 :(得分:1)
您可以使用Date pipe
,这是一个示例:
export class MyComponent implements OnInit {
constructor(private datePipe: DatePipe){}
ngOnInit() {
let start = new Date();
const dateAsString = this.datePipe.transform(start, 'dd-MM-yyyy HH:mm:ss');
console.log(dateAsString)
}
}
注入DatePipe
并转换并在ngOnInit