得到正确的月份格式日期java [英] get the right Month format date java

查看:133
本文介绍了得到正确的月份格式日期java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以提供任何帮助,如何从这样的字符串中获取正确的日期2014-01-10T09:41:16.000 + 0000
我的代码是:

can any help, how to get the right date from an String like this "2014-01-10T09:41:16.000+0000" my code is:

    String strDate = "2014-01-10T09:41:16.000+0000";
    String day = "";
    String format = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
    Locale locale = new Locale("es", "ES");
    SimpleDateFormat formater = new SimpleDateFormat(format, locale);
    formater.setTimeZone(TimeZone.getTimeZone("Europe/Madrid"));

    Calendar cal = Calendar.getInstance();

    try {
        cal.setTimeInMillis(formater.parse(strDate).getTime());
        String offerDate = cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR);
        System.out.println(offerDate);
    } catch (Exception e){
        System.out.println(e.getMessage());
    }

在结果中我给出的结果如下:10-0-2014 ,我希望结果像10-01-2014

in the result i give something like this: "10-0-2014", i want the result like that "10-01-2014"

提前感谢:)

推荐答案

文档说明:


java.util.Calendar.MONTH

java.util.Calendar.MONTH

MONTH public static final int MONTH get的字段编号,设置
表示月份。这是特定于日历的值。格里高利和朱利安日历中一年中的第一个
月是1月
,即0;最后一个取决于一年中的月数。

MONTH public static final int MONTH Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.

- > Calendar.MONTH的计数从0开始

-> Counting starts at 0 for Calendar.MONTH

这篇关于得到正确的月份格式日期java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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