我用的时候:
console.log(moment(1000*60*60*1).format('hh[h] mm[min] ss[sec]'));
Run Code Online (Sandbox Code Playgroud)
我得到2小时0分0秒而不是1小时.
我通过添加.subtract(1,'hour')做了一个解决方法,如下所示:
console.log(moment(1000*60*60*1).subtract(1, 'hour').format('hh[h] mm[min] ss[sec]'));
Run Code Online (Sandbox Code Playgroud)
我还在学习今天找到的这个图书馆.我错过了什么吗?
如果我有毫秒并且我想从中获取格式化的日期,我该怎么办?
所以我有这个简单的组件:
import {
Component,
ViewEncapsulation,
OnInit,
} from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject } from 'rxjs';
@Component({
selector: 'custom-element',
template: '<div>{{ chuckText$ | async }}</div>',
styleUrls: ['./button.component.css'],
encapsulation: ViewEncapsulation.Native
})
export class ButtonComponent implements OnInit {
public chuckText$ = new BehaviorSubject<string>('');
public constructor(
private http: HttpClient
) {
this.chuckText$.next('Default Text');
}
ngOnInit() {
// nothing too fancy, just for testing purpose
this.http.get('https://api.chucknorris.io/jokes/random')
.subscribe((data: any) => {
console.log(data.value);
this.chuckText$.next(data.value);
});
}
}
Run Code Online (Sandbox Code Playgroud)
构建我的组件并将其添加到一个简单的angularJS应用程序后,(我需要将一个自定义元素添加到旧应用程序)我在控制台中使用默认文本和http.get结果获取我的元素,但我的组件尚未被更新,如图所示.
我显然遗漏了一些对我来说不太明显的事情.有关为什么内容不更新的任何想法?作为提醒,这个功能已经发布,但处于实验状态,也许就是这样.
作为参考,这是我的app.module.ts:
import …Run Code Online (Sandbox Code Playgroud)