Java 将时间戳转换为字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26360974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:21:33  来源:igfitidea点击:

Convert timestamp to string

javastringtimestampjoptionpane

提问by user3703289

In java I need to display 'time of the program start'

在java中我需要显示“程序启动时间”

It must be in String.

它必须在String.

How do I get the current time, and then convert it to a String?

如何获取当前时间,然后将其转换为String

采纳答案by amit bhardwaj

try this

尝试这个

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String string  = dateFormat.format(new Date());
System.out.println(string);

you can create any format see this

你可以创建任何格式看到这个

回答by S. Tersteeg

new Date().toString();

新日期().toString();

http://www.mkyong.com/java/java-how-to-get-current-date-time-date-and-calender/

http://www.mkyong.com/java/java-how-to-get-current-date-time-date-and-calender/

Dateformatter can make it to any string you want

Dateformatter 可以把它变成你想要的任何字符串