I want to convert a Date in to Russian and using the code below

SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG,locale).format(date);

where locale is of type Locale

The problem is months are not parsed correctly . January is coming as "январь" it should be "января" and February is coming as "февраль" should be "февраля"

and so on...

One idea is to convert incorrect months to proper ones in my logic

Is there any thing by which Java do this automatically ?

Thanks

解决方案

On my JDK-6-installation I can reproduce your problem:

Date jud = new SimpleDateFormat("yyyy-MM-dd").parse("2014-02-28");

String month =

DateFormat.getDateInstance(SimpleDateFormat.LONG, new Locale("ru")).format(jud);

System.out.println(month); // output: 28 Февраль 2014 г.

Java-8 offers you a solution.

It seems that the JDK has changed the internal default from "standalone-style" (nominative) to "format-style" (genitive).

String date =

DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)

.withLocale(new Locale("ru"))

.format(LocalDate.of(2014, 2, 28));

System.out.println(date); // output: 28 февраля 2014 г.

If you need to apply standalone textstyle then you have to set up your own DateTimeFormatterBuilder which requires a little bit more effort, else TextStyle.FULL should be the default.

String m = Month.FEBRUARY.getDisplayName(TextStyle.FULL , new Locale("ru"));

// февраля (first and last char are different)

String s = Month.FEBRUARY.getDisplayName(TextStyle.FULL_STANDALONE , new Locale("ru"));

// Февраль (this style can be used in DateTimeFormatterBuilder for the month field, too)

Workaround for Java-pre-8 using old style:

Define your own text resources (troublesome)!

Locale russian = new Locale("ru");

String[] newMonths = {

"января", "февраля", "марта", "апреля", "мая", "июня",

"июля", "августа", "сентября", "октября", "ноября", "декабря"};

DateFormatSymbols dfs = DateFormatSymbols.getInstance(russian);

dfs.setMonths(newMonths);

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, russian);

SimpleDateFormat sdf = (SimpleDateFormat) df;

sdf.setDateFormatSymbols(dfs);

Date jud = new SimpleDateFormat("yyyy-MM-dd").parse("2014-02-28");

String month = sdf.format(jud);

System.out.println(month); // output: 28 февраля 2014 г.

Joda-Time does not offer a good solution in a Java-pre-8 environment because it only delegates to JDK. See also a similar issue on Joda-site.

Finally there is also my library

System.out.println(

ChronoFormatter.ofDateStyle(DisplayMode.FULL, new Locale("ru")).format(

PlainDate.of(2014, Month.FEBRUARY, 28)

)

); // output: 28 февраля 2014 г.

java 俄语月份,适当的俄语月字符串翻译Java相关推荐

  1. json 解析 转java对象数组对象数组对象_json字符串转java对象数组

    需要引入json-lib-2.2-jdk15.jar和ezmorph-1.0.6.jar包 String itemStar = request.getParameter("itemStar& ...

  2. java bean jsonobject_利用JSONObject将json 字符串转换为java bean对象

    利用JSONObject将下面这个json字符串转换为javabean对象 { "assetInfoList":[{ "devsno":"xxx&qu ...

  3. java json对象 输出_拼json字符串输出java对象

    @SuppressWarnings("serial") public class AddBankCardLog { private String custno;//客户号 priv ...

  4. java求拼接后的字符串长度,java如何拼接字符串

    java 动态拼接字符串,Java 字符串拼接效率分析及最佳实践,java字符串拼接,java如何拼接字符串 在JAVA 中拼接两个字符串的最简便的方式就是使用操作符"+"了.如果 ...

  5. java list 转json 字符串_JSON的String字符串与Java的List列表对象的相互转换

    1.JSON的String字符串与Java的List列表对象的相互转换 在前端: 1.如果json是List对象转换的,可以直接遍历json,读取数据. 2.如果是需要把前端的List对象转换为jso ...

  6. java当前月份减一个月_Java对日期Date类进行加减运算、年份加减月份加减、时间差等等...

    实现代码一: import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public c ...

  7. Java工具-获取某月份天数、某月最后一天、某月工作日天数(支持自定义节假日)

    Java工具-获取某月份天数.某月最后一天.某月工作日天数(支持自定义节假日) 因为之前在项目中有一个工作日志的功能,所以在网上找了一些相关的工具类,都是零零散散,我在这总结一下.废话不多说,上代码! ...

  8. java 字符串转日历_将字符串转换为Java中的日历对象

    现代方法使用java.time类. YearMonth.from( ZonedDateTime.parse( "Mon Mar 14 16:02:37 GMT 2011" , Da ...

  9. Java 10 正式发布!时隔 6 月带来 109 项新特性

    点击上方"CSDN",选择"置顶公众号" 关键时刻,第一时间送达! 期待已久,没有跳票的 Java 10 已正式发布! 为了更快地迭代,以及跟进社区反馈,Jav ...

最新文章

  1. 发布一个用于WinCE的矢量图控件
  2. 算法学习之路|完美数列
  3. linux 增加 ip_conntrack_max 造成 内核内存问题
  4. springboot整个缓存_SpringBoot中整合Redis(缓存篇)
  5. 说说你对Jdk并发包中的CAS实现的了解?
  6. 基于Spring的包含特定注解bean的package扫描工具
  7. (转)30分钟正则表达式入门
  8. suse linux11安装 dhcp,Suse Linux DHCP的设定过程
  9. PPT 2013 提升演讲逼格 视频教程
  10. Cheat Engine逆向修改植物大战僵尸(外挂)
  11. linux鼠标手势,Vivaldi 1.2 发布,定制鼠标手势
  12. 整合xxl-job-admin动态添加xxl-job定时任务
  13. 前后端分离-小项目-1前端布局
  14. JavaScript利用Date对象实现倒计时效果
  15. 计算机在黑板前面英语怎么写,计算机多媒体在英语教学中的运用
  16. HTML知识点总结还涉及一些subline的基本操作(有很多不足,现为初学者,以后补充)
  17. 国际知名服装品牌网站整理
  18. 新版云盘网盘网站PHP源码+对接云存储/附教程
  19. 【分享】给大家几个免费的上传空间
  20. linux云计算主要就业岗位有哪些

热门文章

  1. android sqlcipher 加密,Android 数据库加密 SQLCipher使用方法
  2. linux挂载硬盘作用,Linux(挂载) mount umount作用
  3. python字符串的美化_shell 下使用python 美化输出json
  4. yum安装jdk1.8
  5. sae中使用django migrate导致13013的问题
  6. 昆仑万维C++工程师笔试
  7. OpenShift 4 - 在集群节点用crictl对Pod/Image/Container进行操作
  8. (二)为自动化MLOps设置GitHub、Docker和Google Cloud Platform
  9. 线程安全的量化时间帧环形缓冲区
  10. .NET Core 3.0中的Cookie身份验证