>我使用矩js和矩Jalali js和角度矩js,我会使用datePicker jalali,当我使用属性locale="fa"时,我使用angular-moment-picker,称我错误无效的贾拉利年3503
我的代码在这里:
<div
moment-picker="profilePet.birthday"
locale="fa"
format="MM/DD/YYYY"
ng-model-options="{ updateOn: 'blur' }">
click me
和控制台内的错误:
Error: "Invalid Jalali year 3503"
为了使用Jalali -moment将时间从公历转换为Jalali,您可以简单地使用此方法:
getDate(gregorianDate) {
let recivedDate = this.formatGregorianDate(gregorianDate);
let Jalali= moment(recivedDate, 'YYYY/MM/DD').lang('en').format('jYYYY/jMM/jDD');
console.log(Jalali);
}
但是因为时间的格式可能不匹配,你可以使用这种方法找到想要的格式,然后使用该方法的结果来输入转换日期:
formatGregorianDate(gregorianDate) {
var date = new Date(gregorianDate);
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
var fullYear = year + '/' + month + '/' + day;
return fullYear;
}
You can create a Pipe for Jalali-moment and add this code in NPM, and use it according to the link =>
Install via NPM:
`npm install jalali-moment -S`
then import in Angular Pipe:
`import * as moment from 'jalali-moment';`
then Pipe content:
@Pipe({
name: 'jalali'
})
export class JalaliPipe implements PipeTransform {
transform(value: any, args?: any): any {
let MomentDate=moment(value);
return MomentDate.format("jYYYY/jM/jD");
}
}
At the end you can look this page :
[https://www.npmjs.com/package/jalali-moment/v/1.0.6][1]
[1]: https://www.npmjs.com/package/jalali-moment/v/1.0.6