تبدیل تاریخ از میلادی به شمسی

PHOTO EMBED

Sat Jul 16 2022 05:05:23 GMT+0000 (Coordinated Universal Time)

Saved by @nimaSm #utils

const date = new Date()
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()

// return [year, month, day]
export function dateConverter(year, month, day) {
    var g_d_m, jy, jm, jd, gy2, days;
    g_d_m = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
    gy2 = (month > 2) ? (year + 1) : year;
    days = 355666 + (365 * year) + ~~((gy2 + 3) / 4) - ~~((gy2 + 99) / 100) + ~~((gy2 + 399) / 400) + day + g_d_m[month - 1];
    jy = -1595 + (33 * ~~(days / 12053));
    days %= 12053;
    jy += 4 * ~~(days / 1461);
    days %= 1461;
    if (days > 365) {
      jy += ~~((days - 1) / 365);
      days = (days - 1) % 365;
    }
    if (days < 186) {
      jm = 1 + ~~(days / 31);
      jd = 1 + (days % 31);
    } else {
      jm = 7 + ~~((days - 186) / 30);
      jd = 1 + ((days - 186) % 30);
    }
  return [jy, jm, jd];
}
content_copyCOPY