提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用SimpleDateFormat将日期字符串从一种格式转换为另一种格式
import java.util.Date;/**来自 N o w J a v a . c o m**/ import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { public static void main(String[] args) { String strDate = "12/12/18"; try { SimpleDateFormat sdfSource = new SimpleDateFormat("dd/MM/yy"); Date date = sdfSource.parse(strDate); SimpleDateFormat sdfDestination = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss"); strDate = sdfDestination.format(date);/*N o w J a v a . c o m - 时 代 Java 提 供*/ System.out.println("Date is converted from dd/MM/yy format to MM-dd-yyyy hh:mm:ss"); System.out.println(