提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用SimpleDateFormat格式化秒
import java.text.SimpleDateFormat; import java.util.Date; /* *来 自 N o w J a v a . c o m */ public class Main { public static void main(String[] args) { Date date = new Date(); //formatting seconds in s format like 1,2 etc. String strDateFormat = "s"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("seconds in s format : " + sdf.format(date)); //formatting seconds in ss format like 01, 02 etc. strDateFormat = "ss";//n o w j a v a . c o m sdf =