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

xiaoxiao2021-02-28  117

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; //返回结果 } }
转载请注明原文地址: https://www.6miu.com/read-33772.html

最新回复(0)