怎么用日期格式化函数生成这样的字符串
2008年11月28日 上午10:00 - 11:30

解决方案 »

  1.   

    先生成"yyyymmdd hhmm"格式的字符串
    再修改、拼接
      

  2.   

    public static void main(String[] args) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd a hh:mm:ss  ");
    Date date = new Date();
    System.out.println(format.format(date));


    }
      

  3.   

     
    public static void main(String[] args) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 a hh:mm:ss  ");
            Date date = new Date();
            System.out.println(format.format(date));
            
            
        }自己看api啊
      

  4.   

    给个例子给你看,汲取里面的道理:
    时间这东西挺简单的,想怎么操作就怎么操作。import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;public class DateFormat { // 需要日期对象和你要设置的时间,这个以分钟计算的。
    private static String getTimeInterval(Date date, int timeInterval) { Calendar cld = Calendar.getInstance();
    cld.setTime(date); String dateStr = getCalendarFormat(cld);
    cld.add(Calendar.MINUTE, timeInterval);
    dateStr += getCalendarFormat(cld);
    return dateStr;
    } private static String getCalendarFormat(Calendar cld) {
    String am_pm = "";
    String strFormat = ""; am_pm = cld.get(Calendar.AM_PM) > 0 ? "下午" : "上午";
    strFormat = "(yyyy年MM月dd日  " + am_pm + " hh:mm)"; SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
    return sdf.format(cld.getTime());
    } public static void main(String[] args) {
    // 参数是,当前系统时间和60分钟后
    System.out.println("从现在到60分钟后的时间:\n" + getTimeInterval(new Date(), 60));
    // 参数是,当前系统时间和90分钟后
    System.out.println("从现在到90分钟后的时间:\n" + getTimeInterval(new Date(), 90));
    }
    }
      

  5.   

    public static void main(String[] args) { 
            SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 a hh:mm:ss  "); 
            Date date = new Date(); 
            System.out.println(format.format(date)); 
            
            
        }  Calendar 

    DateUtils
      

  6.   

    yyyymmdd hhmm 生成这种格式然后再判断下就OK了上午下午