日期转换和操作在JavaScript与阿拉伯语月 [英] Date conversion and manipulation in javascript with Arabic months

查看:311
本文介绍了日期转换和操作在JavaScript与阿拉伯语月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变一个阿拉伯语的长格式日期,即

I want to change an arabic long-form date, i.e.

الخميس 26 فبراير 2015

(Thursday 26th February, 2015)

使用标准的JavaScript进行标准日期,以便操纵日期(添加一天),然后通过 Date.toLocaleDateString()显示以将其转换回来,使

into a standard date using standard Javascript in order to manipulate the date (add a day), then display via Date.toLocaleDateString() to convert it back, making

2015 الخميس 27 فبراير

(Friday 27th February, 2015)

这是一个将日期字符串分开的情况,将阿拉伯文本解释为月数,并创建一个新的Date()给定的数字,还是有一个将阿拉伯数字字符串转换为javascript日期的原型?需要在 Date.toLocaleDateString()中使用什么语言和可选参数来生成与阿拉伯数据相同的格式,就像在阿拉伯地区使用ar一样,相对于所需的西方数字?

Is this a case of picking the date string apart, interpreting the arabic text as a month number and creating a new Date() given the numbers, or is there a prototype that converts an arabic date string into a javascript date? What language and optional parameters need to be used for Date.toLocaleDateString() to produce the same format of arabic date, as using 'ar' the numbers are returned in eastern arabic, as opposed to the required western numerals?

推荐答案

var months = ["يناير", "فبراير", "مارس", "إبريل", "مايو", "يونيو",
              "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"];

var days =["اﻷحد","اﻷثنين","الثلاثاء","اﻷربعاء","الخميس","الجمعة","السبت"];

var date = new Date();

console.log("The current month is " + months[date.getMonth()]);
console.log("The current day is " + days[date.getDay()]);

这篇关于日期转换和操作在JavaScript与阿拉伯语月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆