将java.util.Date转换为String

将java.util.Date转换为String,第1张

将java.util.Date转换为String

转换日期字符串使用

DateFormat#format
方法:

String pattern = "MM/dd/yyyy HH:mm:ss";// Create an instance of SimpleDateFormat used for formatting // the string representation of date according to the chosen patternDateFormat df = new SimpleDateFormat(pattern);// Get the today date using Calendar object.Date today = Calendar.getInstance().getTime();        // Using DateFormat format method we can create a string // representation of a date with the defined format.String todayAsString = df.format(today);// Print the result!System.out.println("Today is: " + todayAsString);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5021575.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存