将波斯 (Jalali) 日历转换为表单字段条目上的时间戳

发布于 2025-01-10 19:55:46 字数 388 浏览 1 评论 0原文

我在 Confluence 中使用 Confiforms 制作了一个表单,其中包括波斯日历字段。有一个过滤器控制宏来过滤记录。但此过滤器不适用于波斯日期。因为波斯日期保存为时间戳,但波斯日历字段显示日期,而不是时间戳,当我想过滤记录时,我应该在波斯日历字段中写入时间戳以使过滤器起作用。

表单屏幕截图

问题是我希望当我选择一个日期时,它会将其时间戳返回给字段而不是日期。 (见图)

是否有任何 JavaScript/jQuery 代码可以将字段的波斯日期条目转换为时间戳?

编辑: 字段输入的 shamsi 日期格式为 dm-yy(例如 15-12-1400)

I made a form with Confiforms in Confluence including a Persian calendar field. There is a Filter Control macro to filter the records. But this filter doesn't work fine with Persian dates. Because Persian dates are saved as timestamp but the Persian calendar field displays the date, not the timestamp, and when I want to filter records, I should write timestamp in the Persian calendar field to make filter work.

Form ScreenShot

The problem is I want that when I choose a date, it returned its timestamp to the field instead of date. (See the picture)

Is there any JavaScript/jQuery code to convert a Persian date entry of a field to timestamp?

Edit:
The shamsi date format of field entry is d-m-yy (eg. 15-12-1400)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2025-01-17 19:55:46

以下函数将把波斯 (Jalali) 日期转换为时间戳(基于 UTC)。

您将 Jalali 的年、月和日传递给函数,输出是 UTC 区域中的时间戳。

function jalaliToUTCTimeStamp(year, month, day) {
const format=new Intl.DateTimeFormat('en-u-ca-persian',{dateStyle:'short',timeZone:"UTC"});
let g=new Date(Date.UTC(2000,month,day));
    g=new Date(g.setUTCDate(g.getUTCDate()+226867));
const gY=g.getUTCFullYear(g)-2000+year;
    g=new Date(((gY<0)?"-":"+")+("00000"+Math.abs(gY)).slice(-6)+"-"+("0"+(g.getUTCMonth(g)+1)).slice(-2)+"-"+("0"+(g.getUTCDate(g))).slice(-2));
let [pM,pD,pY] = [...format.format(g).split("/")],i=0;
    g=new Date(g.setUTCDate(g.getUTCDate()+~~(year*365.25+month*30.44+day-(pY.split(" ")[0]*365.25+pM*30.44+pD*1))-2));
while (i<4){
[pM,pD,pY]=[...format.format(g).split("/")];
if(pD==day && pM==month && pY.split(" ")[0]==year)return +g;
g=new Date(g.setUTCDate(g.getUTCDate()+1)); i++;
}
throw new Error('Invalid Persian Date!');
}
//==========================================================
// Test Units
//==========================================================
console.log(jalaliToUTCTimeStamp(1400,12,5));
console.log(jalaliToUTCTimeStamp(1400,12,6));
console.log(jalaliToUTCTimeStamp(1400,12,7));
console.log(jalaliToUTCTimeStamp(1400,12,8));
console.log(jalaliToUTCTimeStamp(1400,12,9));
console.log(jalaliToUTCTimeStamp(1400,12,10));
console.log(jalaliToUTCTimeStamp(1400,12,11));
//==========================================================

The following function will convert a Persian (Jalali) Date to a Timestamp (UTC based).

You pass the Jalali's year, month, and day to the function and the output is the timestamp in the UTC zone.

function jalaliToUTCTimeStamp(year, month, day) {
const format=new Intl.DateTimeFormat('en-u-ca-persian',{dateStyle:'short',timeZone:"UTC"});
let g=new Date(Date.UTC(2000,month,day));
    g=new Date(g.setUTCDate(g.getUTCDate()+226867));
const gY=g.getUTCFullYear(g)-2000+year;
    g=new Date(((gY<0)?"-":"+")+("00000"+Math.abs(gY)).slice(-6)+"-"+("0"+(g.getUTCMonth(g)+1)).slice(-2)+"-"+("0"+(g.getUTCDate(g))).slice(-2));
let [pM,pD,pY] = [...format.format(g).split("/")],i=0;
    g=new Date(g.setUTCDate(g.getUTCDate()+~~(year*365.25+month*30.44+day-(pY.split(" ")[0]*365.25+pM*30.44+pD*1))-2));
while (i<4){
[pM,pD,pY]=[...format.format(g).split("/")];
if(pD==day && pM==month && pY.split(" ")[0]==year)return +g;
g=new Date(g.setUTCDate(g.getUTCDate()+1)); i++;
}
throw new Error('Invalid Persian Date!');
}
//==========================================================
// Test Units
//==========================================================
console.log(jalaliToUTCTimeStamp(1400,12,5));
console.log(jalaliToUTCTimeStamp(1400,12,6));
console.log(jalaliToUTCTimeStamp(1400,12,7));
console.log(jalaliToUTCTimeStamp(1400,12,8));
console.log(jalaliToUTCTimeStamp(1400,12,9));
console.log(jalaliToUTCTimeStamp(1400,12,10));
console.log(jalaliToUTCTimeStamp(1400,12,11));
//==========================================================

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文