How do you convert a Unix timestamp to Jalali/Shamsi/Persian format?(如何将 Unix 时间戳转换为 Jalali/Shamsi/Persian 格式?)
问题描述
我正在开发一个网络应用程序,并且我有一个 unix 时间戳.我需要使用 jQuery 选择器将 unix 日期格式转换为 Jalali/Persian/Shamsi 日历,然后使用 javascript 库进行转换.
下面的代码将 Unix-Date
转换为 Jalali-Date
:
I'm developing a web App and I have a unix timeStamp.
I need to convert a unix date format to Jalali/Persian/Shamsi Calendar by using jQuery selectors and then convert it by using javascript library.
Something Like below code to convert Unix-Date
to Jalali-Date
:
我搜索但没有找到任何好的图书馆.您知道用于转换(或从 unix 时间戳创建 Jalali 格式的日期)的可靠且良好的库吗?我不需要你的实现或算法,因为这个问题太 bug 并且有很多规则,我需要一个可靠的解决方案.
I searched but didn't found any good library. Do you know a reliable and good library for converting (or creating dates in Jalali format from a unix timeStamp). I don't need your implementation or an algorithm, cause this issue is too buggy and has a lot of rules, I need a reliable solution.
谢谢
推荐答案
我建议使用 moment.js
(https://momentjs.com/),这是一个可靠的 JavaScript 时间库,允许您在 JavaScript 中格式化您的时间戳.下面是一个示例,说明如何解析时间戳并将其格式化为您想要使用的任何格式.
I would suggest using moment.js
(https://momentjs.com/) which is reliable JavaScript Time library that allows you to format your timestamp in JavaScript. Below is an example of how you can parse a timestamp and format it to whatever you want using it.
您还标记了可以通过使用来完成的本地化;
You also tagged localization which can be done by using;
更多示例可以在该网站上找到.
More examples can be found on there website.
这与 https://www.npmjs.com/package/jalali-date 会给你你的 jalali 日期.
This in conjunction with https://www.npmjs.com/package/jalali-date will get you your jalali date.
这里还有一个波斯语的 moment.js 扩展 https://www.npmjs.com/package/moment-jalaali(从时刻到 Jalali)
There is a moment.js extension for Persian here also https://www.npmjs.com/package/moment-jalaali (From moment to Jalali)
另一个 Jalali 转换库 https://www.npmjs.com/package/jalaali-js(致贾莱)
Another Jalali conversion library https://www.npmjs.com/package/jalaali-js (To Jalai)
使用从 Unix 时间戳转换的 moment.js Jalali 的示例小提琴 https://jsfiddle.net/uw82ozpd/9/
An example fiddle using moment.js Jalali conversion from Unix Timestamp https://jsfiddle.net/uw82ozpd/9/
带注释的相关代码段:
这篇关于如何将 Unix 时间戳转换为 Jalali/Shamsi/Persian 格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!