Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert UNIX Timestamp To Jalali Calendar

I want convert unix timestamp date to jalai calendar with jquery , i want set unix timestamp in attribute html tag and then show in tag

example:

1400/03/18 18:35:40

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can easily use the following code :

Put the unix timestamp value in the attribute

<h1 unix_timestamp="1520482240"></h1>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
        $('[unix_timestamp]').each(function () {
            var unixtimestamp = $(this).attr("unix_timestamp");
            if (unixtimestamp != null) {
                let today = new Date(eval(unixtimestamp * 1000)).toLocaleDateString('fa-IR');
                var date = new Date(unixtimestamp * 1000);
                var hours = date.getHours();
                var minutes = "0" + date.getMinutes();
                var seconds = "0" + date.getSeconds();
                var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
                $(this).html(today + " " + formattedTime);
            }
        });
</script>

You can use it for any tag

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading