- This topic is empty.
- AuthorPosts
-
November 29, 2016 at 6:31 am #9419
shebinParticipantI want the date to be formatted in the following format:
date: 2016-12-04 into Ø§Ù„Ø£ØØ¯ØŒ 4 ديسمبر، 2016
But I’m getting the following. The numbers are converted to Arabic numerals. I want the date and year in English numerals:
Ø§Ù„Ø£ØØ¯ØŒ Ù¤ ديسمبر، ٢٠١٦
I have used the following code to format the date to Arabic.
var date = new Date('2016-12-04'); options = { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric', }; var dateString = date.toLocaleDateString('ar-SA', options); alert(dateString);November 29, 2016 at 6:42 am #9423
shebinParticipantFound a solution Date conversion and manipulation in javascript with Arabic months
My modified code to get my desired output is as follows.
var date = new Date('2016-12-04'); var months = ["يناير", "ÙØ¨Ø±Ø§ÙŠØ±", "مارس", "إبريل", "مايو", "يونيو", "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوÙمبر", "ديسمبر" ]; var days = ["Ø§ï»·ØØ¯", "اﻷثنين", "الثلاثاء", "اﻷربعاء", "الخميس", "الجمعة", "السبت"]; var delDateString = days[date.getDay()] + ', ' + date.getDate() + ' ' + months[date.getMonth()] + ', ' + date.getFullYear(); console.log(delDateString); // Outputs Ø§ï»·ØØ¯, 4 ديسمبر, 2016November 29, 2016 at 6:52 am #9420
sarmadParticipantTry ‘ar-MA’ (for Morocco) instead of ‘ar-SA’.
November 17, 2019 at 3:28 am #9424
omar-abdelhadyParticipantYou can use this Locales to specify numbering system.
let date = newDate.toLocaleDateString('ar-EG-u-nu-latn',{weekday: 'long', year: 'numeric', month: 'short', day: 'numeric'});also check this MDN link to know more about it
September 11, 2021 at 4:50 am #9421
ali-seyfollahiParticipantTo get the current hijri date in javascript, we can use
Intl.DateTimeFormatTo get the arabic display :
new Intl.DateTimeFormat('ar-TN-u-ca-islamic', {day: 'numeric', month: 'long',weekday: 'long',year : 'numeric'}).format(Date.now());the expected output :
السبت، 4 ØµÙØ± 1443 هـhttps://medium.com/@Saf_Bes/get-today-hijri-date-in-javascript-90855d3cd45b
January 28, 2022 at 3:36 am #9422
mohsen-alyafeiParticipantA better (safer) way to get the Hijri (Islamic) date in English Numerals (Western-Arabic Numbers) in javascript is NOT to use a specific country locale like "ar-SA" or "ar-TN" or "ar-EG"; but use the Intl.DateTimeFormat() constructor with the following
Locale options:-
The numbering system (nu) set to
latn(i.e. Western-Arabic Numbers), and -
Calendar type (ca) set to
islamic, and -
The language locale to
ar
The Locale options can be passed as an array for multiple options:
["ar-u-ca-islamic","ar-u-nu-latn"]or as one string :
"ar-u-ca-islamic-nu-latn"Here is an example code that will print today’s Hijri (Islamic) date with Western-Arabic Numbers (English Numerals):
I have also included a table to give the list of all Arabic "ar" locales and the default outputs to see the difference between them with regards to the name of the months and the default number system.
let options = {day: 'numeric', month: 'long',weekday:'long',year:'numeric'}; // 1st method let locales = ["ar-u-ca-islamic","ar-u-nu-latn"]; console.log(new Intl.DateTimeFormat(locales, options).format(Date.now())); // 2nd method locales = "ar-u-ca-islamic-nu-latn"; console.log(new Intl.DateTimeFormat(locales, options).format(Date.now())); -
- AuthorPosts
- You must be logged in to reply to this topic.