得到格式化的时间

1、java.util.date类实现,

public String getTime() {
        //得到format对象
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        //得到Date对象
        Date curDate = new Date();
        String str = format.format(curDate);
        return str;
    }

2、Java中Calendar类实现

public String getTime() {
          Calendar calendar = Calendar.getInstance();  
    String created = calendar.get(Calendar.YEAR) + "年"  
            + (calendar.get(Calendar.MONTH)+1) + "月"//从0开始计算 
            + calendar.get(Calendar.DAY_OF_MONTH) + "日"  
            + calendar.get(Calendar.HOUR_OF_DAY) + "时"  //分24小时制
            + calendat.get(Calendar.HOUR)+"时"//12小时制
            + calendar.get(Calendar.MINUTE) + "分"+calendar.get(Calendar.SECOND)+"s"; 
    }

你可能感兴趣的:(格式化时间)