java编程题:将某个时间以固定格式转化成字符串

来源:互联网 发布:淘宝七天下架什么意思 编辑:程序博客网 时间:2024/05/16 15:39

/** * java编程题:将某个时间以固定格式转化成字符串  */public class Test {public static void main(String[] args) {Date now = new Date();//当前时间System.out.println(formatDateToString(now));//打印结果}private static String formatDateToString(Date date){//定义字符串格式SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String dateStr = sdf.format(date);// 格式化日期,并得到字符串return dateStr;// 返回结果}}



0 0
原创粉丝点击