在java中,怎么将“9月23日 16:00”这样的字符串格式化成日期

解决方案 »

  1.   

    SimpleDateFormat("yyyy年MM月 HH:mm")
    format()就行了
      

  2.   

    你没有年,你的自己把当前的年加上去。可以用
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);拿到当前的年
      

  3.   

    code:
                    String xsDate="9月23日 16:00";
    SimpleDateFormat sd = new SimpleDateFormat("MM月dd日 HH:mm");
    SimpleDateFormat sd1 = new SimpleDateFormat("yyyy年MM月dd hh:mm");//返回的年是1970年,可以理解,一開始供解析的字符串也未包含年
    SimpleDateFormat sd2 = new SimpleDateFormat("MM月dd HH:mm");
    SimpleDateFormat sd3 = new SimpleDateFormat("MM月dd hh:mm");
    SimpleDateFormat sd4 = new SimpleDateFormat("MM月dd h:mm a");
    System.out.println(sd1.format(sd.parse(xsDate)));
    System.out.println(sd2.format(sd.parse(xsDate)));
    System.out.println(sd3.format(sd.parse(xsDate)));
    System.out.println(sd4.format(sd.parse(xsDate)));
    上述代码为示例,取得当前年参照上楼
    如果转换后的格式不满意,参照SimpleDateFormat类的说明再改改
      

  4.   

    SimpleDateFormat(日期格式)
    .format(日期);
      

  5.   

    罗列的差不多了,一般有4中形式,jdk定义的,short long 还有2中忘记了,自己也可以定义的,如上
      

  6.   

    // 此处的月份要用大写的MM,小写的mm表示分钟
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
    Calendar cc = Calendar.getInstance();
    // 获取当前时间并格式化之
    String newDate = sdf.format(cc.getTime());
    System.out.println(newDate);
      

  7.   

    天狼工作室
    http://www.j2soft.cn    //***************************************************
        //名称:strToDate
        //功能:将指定的字符串转换成日期
        //输入:aStrValue: 要转换的字符串; 
        // aFmtDate: 转换日期的格式, 默认为:"yyyy/MM/dd"
        //      aDteRtn: 转换后的日期
        //输出:
        //返回:TRUE: 是正确的日期格式; FALSE: 是错误的日期格式
        //***************************************************
        public static boolean strToDate(
            String aStrValue,
            String aFmtDate,
            java.util.Date aDteRtn)
        {
            if (aFmtDate.length() == 0)
            {
                aFmtDate = "yyyy/MM/dd";
            }
            SimpleDateFormat fmtDate = new SimpleDateFormat(aFmtDate);
            try
            {
                aDteRtn.setTime(fmtDate.parse(aStrValue).getTime());
            }
            catch (Exception e)
            {
                return (false);
            }        return (true);
        }