时间以固定格式转化为字符串

来源:互联网 发布:蜂鸟软件科技有限公司 编辑:程序博客网 时间:2024/05/21 22:27
import java.text.SimpleDateFormat;import java.util.Date;/** * 将某个时间以固定格式转化为字符串 * @author Administrator * */public class zh {    public static void main(String[] args) {        Date now =new Date();        System.out.println(date2FormatStr(now));    }    //得到固定字符串格式的方法    public static String date2FormatStr(Date date){        //定义字符串的格式        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        String str = sdf.format(date);                      //进行格式化,并得到字符串        return str;                                         //返回结果    }}
1 0
原创粉丝点击