• <bdo id='ZHnwH'></bdo><ul id='ZHnwH'></ul>

      <tfoot id='ZHnwH'></tfoot>
        <legend id='ZHnwH'><style id='ZHnwH'><dir id='ZHnwH'><q id='ZHnwH'></q></dir></style></legend>
      1. <small id='ZHnwH'></small><noframes id='ZHnwH'>

        <i id='ZHnwH'><tr id='ZHnwH'><dt id='ZHnwH'><q id='ZHnwH'><span id='ZHnwH'><b id='ZHnwH'><form id='ZHnwH'><ins id='ZHnwH'></ins><ul id='ZHnwH'></ul><sub id='ZHnwH'></sub></form><legend id='ZHnwH'></legend><bdo id='ZHnwH'><pre id='ZHnwH'><center id='ZHnwH'></center></pre></bdo></b><th id='ZHnwH'></th></span></q></dt></tr></i><div id='ZHnwH'><tfoot id='ZHnwH'></tfoot><dl id='ZHnwH'><fieldset id='ZHnwH'></fieldset></dl></div>

        将 gregorian 日期转换为 angular 2 和 Ionic 2 中的波斯

        时间:2023-09-08
      2. <tfoot id='ON0SI'></tfoot>
        1. <legend id='ON0SI'><style id='ON0SI'><dir id='ON0SI'><q id='ON0SI'></q></dir></style></legend>
          <i id='ON0SI'><tr id='ON0SI'><dt id='ON0SI'><q id='ON0SI'><span id='ON0SI'><b id='ON0SI'><form id='ON0SI'><ins id='ON0SI'></ins><ul id='ON0SI'></ul><sub id='ON0SI'></sub></form><legend id='ON0SI'></legend><bdo id='ON0SI'><pre id='ON0SI'><center id='ON0SI'></center></pre></bdo></b><th id='ON0SI'></th></span></q></dt></tr></i><div id='ON0SI'><tfoot id='ON0SI'></tfoot><dl id='ON0SI'><fieldset id='ON0SI'></fieldset></dl></div>

              <small id='ON0SI'></small><noframes id='ON0SI'>

                • <bdo id='ON0SI'></bdo><ul id='ON0SI'></ul>
                    <tbody id='ON0SI'></tbody>
                  本文介绍了将 gregorian 日期转换为 angular 2 和 Ionic 2 中的波斯(jalali)日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我熟悉位于 npm 中的一个包,用于将公历日期转换为波斯语 (jalali),但我不知道应该如何在 ionic 2 angular 2 项目中使用它.

                  I'm familiar with one package located in npm for converting gregorian date to persian (jalali), but i don't know how should i use it in ionic 2 angular 2 projects.

                  Jalali-date

                  或角度 1 的这个包:

                  or this package for angular 1:

                  ADM-dateTimePicker

                  是否可以将此包转换为 angular 2?任何的想法?欢迎或教程...

                  is it possible to convert this package to angular 2? any idea? or tutorial are welcome...

                  推荐答案

                  好的,我为此写了转换器,

                  ok, i wrote convertor for this purpose,

                  首先在你的项目中添加一个提供者:

                  first add a provider in your project:

                  import {Injectable} from '@angular/core';
                  @Injectable()
                  export class PersianCalendarService {
                    weekDayNames: string[] = ["شنبه", "یکشنبه", "دوشنبه",
                      "سه شنبه", "چهارشنبه",
                      "پنج شنبه", "جمعه"];
                    monthNames: string[] = [
                      "فروردین",
                      "اردیبهشت",
                      "خرداد",
                      "تیر",
                      "مرداد",
                      "شهریور",
                      "مهر",
                      "آبان",
                      "آذر",
                      "دی",
                      "بهمن",
                      "اسفند"];
                    strWeekDay: string = null;
                    strMonth: string = null;
                    day: number = null;
                    month: number = null;
                    year: number = null;
                    ld: number = null;
                    farsiDate: string = null;
                  
                    today: Date = new Date();
                  
                    gregorianYear = null;
                    gregorianMonth = null;
                    gregorianDate = null;
                    WeekDay = null;
                    buf1: number[] = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
                    buf2: number[] = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
                  
                    constructor() {
                    }
                    PersianCalendar(gregorianDate): string {
                      this.today = gregorianDate;
                      this.gregorianYear = this.today.getFullYear();
                      this.gregorianMonth = this.today.getMonth() + 1;
                      this.gregorianDate = this.today.getDate();
                      this.WeekDay = this.today.getDay();
                      this.toPersian(gregorianDate);
                      return this.strWeekDay + " " + this.day + " " + this.strMonth + " " + this.year;
                  
                  
                    }
                    toPersian(gregorianDate) {
                      if ((this.gregorianYear % 4) != 0)
                        this.farsiDate = this.func1();
                      else
                        this.farsiDate = this.func2();
                      this.strMonth = this.monthNames[Math.floor(this.month - 1)];
                      this.strWeekDay = this.weekDayNames[this.WeekDay + 1];
                  
                    }
                  
                  
                    func1(): string {
                      this.day = this.buf1[this.gregorianMonth - 1] + this.gregorianDate;
                      if (this.day > 79) {
                        this.day = this.day - 79;
                        if (this.day <= 186) {
                          var day2 = this.day;
                          this.month = (day2 / 31) + 1;
                          this.day = (day2 % 31);
                          if (day2 % 31 == 0) {
                            this.month--;
                            this.day = 31;
                          }
                          this.year = this.gregorianYear - 621;
                        }
                        else {
                          var day2 = this.day - 186;
                          this.month = (day2 / 30) + 7;
                          this.day = (day2 % 30);
                          if (day2 % 30 == 0) {
                            this.month = (day2 / 30) + 6;
                            this.day = 30;
                          }
                          this.year = this.gregorianYear - 621;
                        }
                      }
                      else {
                        this.ld = this.gregorianYear > 1996 && this.gregorianYear % 4 == 1 ? 11 : 10;
                        var day2 = this.day + this.ld;
                        this.month = (day2 / 30) + 10;
                        this.day = (day2 % 30);
                        if (day2 % 30 == 0) {
                          this.month--;
                          this.day = 30;
                        }
                        this.year = this.gregorianYear - 622;
                      }
                      var fullDate = this.day + "/" + Math.floor(this.month) + "/" + this.year;
                      return fullDate
                    }
                  
                  
                  
                    func2(): string {
                      //console.log("entered func2");
                      this.day = this.buf2[this.gregorianMonth - 1] + this.gregorianDate;
                      this.ld = this.gregorianYear >= 1996 ? 79 : 80;
                      if (this.day > this.ld) {
                        this.day = this.day - this.ld;
                        if (this.day <= 186) {
                          var day2 = this.day;
                          this.month = (day2 / 31) + 1;
                          this.day = (day2 % 31);
                          if (day2 % 31 == 0) {
                            this.month--;
                            this.day = 31;
                          }
                          this.year = this.gregorianYear - 621;
                        } else {
                          var day2 = this.day - 186;
                          this.month = (day2 / 30) + 7;
                          this.day = (day2 % 30);
                          if (day2 % 30 == 0) {
                            this.month--;
                            this.day = 30;
                          }
                          this.year = this.gregorianYear - 621;
                        }
                        var fullDate = this.day + "/" + Math.floor(this.month) + "/" + this.year;
                        return fullDate
                      }
                      else {
                        var day2 = this.day + 10;
                        this.month = (day2 / 30) + 10;
                        this.day = (day2 % 30);
                        if (day2 % 30 == 0) {
                          this.month--;
                          this.day = 30;
                        }
                        this.year = this.gregorianYear - 622;
                      }
                    }
                  }
                  

                  下一步:在您的代码中导入此服务:

                  the next step: import this service in your code:

                  import {PersianCalendarService} from '../../providers/persian-calendar-service/persian-calendar-service';
                  

                  下一步:在 @Page 部分实现提供者的名称

                  the next step: implement the provider's name in @Page section

                  @Page({
                    templateUrl: 'build/pages/getting-started/getting-started.html',
                    providers: [PersianCalendarService]
                  })
                  

                  构造函数

                  constructor(
                     public persianCalendarService: PersianCalendarService) {}
                  

                  那么您只需将日期传递给函数以获得良好的 Jalali 日期输出:

                  then just you need to pass the date to the function for getting a nice output of Jalali date:

                   getJalaliDate(date) {
                  var date1 = this.persianCalendarService.PersianCalendar(date);
                  this.farsiDate = date1;
                  

                  }

                  我会尽快将这段代码添加到 github 中.谢谢

                  i'll add this code in github soon. Thanks

                  这篇关于将 gregorian 日期转换为 angular 2 和 Ionic 2 中的波斯(jalali)日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Ionic 2:在标签按钮中使用图片 下一篇:使用模态和样式的 Ionic 2 登录弹出窗口

                  相关文章

                  最新文章

                    <bdo id='GeRQk'></bdo><ul id='GeRQk'></ul>
                • <i id='GeRQk'><tr id='GeRQk'><dt id='GeRQk'><q id='GeRQk'><span id='GeRQk'><b id='GeRQk'><form id='GeRQk'><ins id='GeRQk'></ins><ul id='GeRQk'></ul><sub id='GeRQk'></sub></form><legend id='GeRQk'></legend><bdo id='GeRQk'><pre id='GeRQk'><center id='GeRQk'></center></pre></bdo></b><th id='GeRQk'></th></span></q></dt></tr></i><div id='GeRQk'><tfoot id='GeRQk'></tfoot><dl id='GeRQk'><fieldset id='GeRQk'></fieldset></dl></div>
                • <tfoot id='GeRQk'></tfoot>

                    1. <small id='GeRQk'></small><noframes id='GeRQk'>

                      <legend id='GeRQk'><style id='GeRQk'><dir id='GeRQk'><q id='GeRQk'></q></dir></style></legend>