Android擷取目前時間
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | SimpleDateFormat formatter= new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss "); Date curDate = new Date(System.currentTimeMillis());//擷取目前時間 String str = formatter.format(curDate); 1.2 SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String date= sDateFormat.format(new Date()); 1.3 單獨擷取年月或者時分 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM"); String date=sdf.format(new Date()); SimpleDateFormat sdf=new SimpleDateFormat("hh:mm:ss"); String date=sdf.format(new Date()); |