typescript - Angular2'de saniyeleri zaman stringine nasıl dönüştürebilirim?
Bu yüzden tüm internette bu işlevi arıyordum ve saniyeleri yıl, ay, gün, saat, dakika ve saniye olarak bir string şeklinde temsil edilebilecek bir çözüme dönüştürebileceğim bir çözüm bulamadım.
Cevap #1
Angular2'de bir Pipe çözümü buldum, ancak bunu geliştirmek için nelerin daha iyi yapılabileceği hakkında bazı geri bildirimler almak istiyorum.
Ayrıca belki başka bazı insanlar da bu tür bir boruya ihtiyaç duyabilir, bu yüzden paylaşmak için burada bırakıyorum.
import {Pipe} from "angular2/core";
@Pipe({
name: 'secondsToTime'
})
export class secondsToTimePipe{
times = {
year: 31557600,
month: 2629746,
day: 86400,
hour: 3600,
minute: 60,
second: 1
}
transform(seconds){
let time_string: string = '';
let plural: string = '';
for(var key in this.times){
if(Math.floor(seconds / this.times[key]) > 0){
if(Math.floor(seconds / this.times[key]) >1 ){
plural = 's';
}
else{
plural = '';
}
time_string += Math.floor(seconds / this.times[key]).toString() + ' ' + key.toString() + plural + ' ';
seconds = seconds - this.times[key] * Math.floor(seconds / this.times[key]);
}
}
return time_string;
}
}
