Berikut adalah contoh untuk merubah format menit dalam class simpleDateFormat, format menit bisa dirubah dalam 'm' ata 'mm', m akan tampil 1 digit bila menit menunjukan 1 digit sedangkan mm akan menampilkan 2 digit
m akan tampil 3
mm akan tampil 03
oke berikut contoh programnya
Nama file : contoh_Minute_Dateformat.java
import java.text.SimpleDateFormat;
import java.util.Date;
public class contoh_Minute_Dateformat {
public static void main(String[] args) {
//create Date object
Date date = new Date();
//formatting minute in m format like 1,2 etc.
String strDateFormat = "m";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
System.out.println("minutes in m format : " + sdf.format(date));
//formatting minutes in mm format like 01, 02 etc.
strDateFormat = "mm";
sdf = new SimpleDateFormat(strDateFormat);
System.out.println("minutes in mm format : " + sdf.format(date));
}
}
Output
run:
minutes in m format : 2
minutes in mm format : 02
BUILD SUCCESSFUL (total time: 1 second)
program dibuat menggunakan netbeans, selamat mencoba semoga bermanfaat ...
No comments:
Post a Comment