读书人

时间格式化模式由Date对象生成Calan

发布时间: 2012-12-24 10:43:14 作者: rapoo

时间格式化方式,由Date对象生成Calander对象

package com.single;import java.io.File;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Calendar;public class TestIo{    public static final String SDF_STYLE_SPECIAL_CHAR = "yyyy-MM-dd HH:mm:ss";    public static final String SDF_STYLE_NO_SPACING = "yyyyMMddHHmmss";    public static final String SDF_SHORT_STYLE_SPECIAL_CHAR = "HH:mm:ss";    public static final String SDF_SHORT_STYLE_NO_SPACING = "HHmmss";    public static void main(String[] args) throws IOException    {        File f = new File("f:/abc/abc.txt");        f.createNewFile();        //利用时间构造calander就应该这样,f.lastModified()获取的是一个long类型 (new Date()).getTime()也是一个long类型        Calendar c = Calendar.getInstance();        c.setTimeInMillis(f.lastModified());                SimpleDateFormat fmt1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        // SimpleDateFormat dateFormate = new SimpleDateFormat("yyyyMMddHHmmss");        // 日期格式        SimpleDateFormat dateFormate = new SimpleDateFormat("yyyy-MM-dd");        // 日期时间格式        SimpleDateFormat dateTimeFormate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        /*有冒号时间格式*/        SimpleDateFormat xx = new SimpleDateFormat("HH:mm:ss");        /*无冒号时间格式*/        SimpleDateFormat ccc = new SimpleDateFormat("HHmmss");                System.out.println(fmt1.format(c.getTime()));    }}

?

读书人网 >编程

热点推荐