Membuat tanggal di Java - Java - Publisher - Royz Rambo
Ilham Penta
Site menu
Section categories
My articles [6]
Java [14]
Java Programming
Flash [6]
Flash
URL web dan Tutorial [29]
Petualangan [1]
Our poll
Rate my site
Total of answers: 19
Statistics

Total online: 1
Guests: 1
Users: 0
Login form
Main » Articles » Java

Membuat tanggal di Java

Siapkan komponen taxtfield atau label, 

public void jam(){
ActionListener taskPerformer = new ActionListener() {

public void actionPerformed(ActionEvent e) {
String nol_bulan = "";
String nol_hari = "";
String nol_jam = "";
String nol_menit = "";
String nol_detik = "";
//membuat calender
Calendar dt = Calendar.getInstance();
//mengambil nilai jam, menit, detik sekarang
int nilai_tahun = dt.get(dt.YEAR);
int nilai_bulan = dt.get(dt.MONTH);
int nilai_hari = dt.get(dt.DAY_OF_MONTH);
int nilai_jam = dt.get(dt.HOUR_OF_DAY);
int nilai_menit = dt.get(dt.MINUTE);
int nilai_detik = dt.get(dt.SECOND);
//jika nilai jam lebih kecil dari 10 (hanya 1 digit)
if (nilai_bulan <= 9) {
nol_bulan = "0";
}
if (nilai_hari <= 9) {
nol_hari = "0";
}
if (nilai_jam <= 9) {
nol_jam = "0";
}
if (nilai_menit <= 9) {
nol_menit = "0";
}
if (nilai_detik <= 9) {
nol_detik = "0";
}
String bulan = nol_bulan + Integer.toString(nilai_bulan + 1);
String hari = nol_hari + Integer.toString(nilai_hari);
String jam = nol_jam + Integer.toString(nilai_jam);
String menit = nol_menit + Integer.toString(nilai_menit);
String detik = nol_detik + Integer.toString(nilai_detik);

switch(nilai_bulan){
case 1:
namaBulan = "Januari"; break;
case 2:
namaBulan = "Februari"; break;
case 3:
namaBulan = "Maret"; break;
case 4:
namaBulan = "April"; break;
case 5:
namaBulan = "Mei"; break;
case 6:
namaBulan = "Juni";break;
case 7:
namaBulan = "Juli"; break;
case 8:
namaBulan = "Agustus"; break;
case 9:
namaBulan = "September"; break;
case 10:
namaBulan = "Oktober"; break;
case 11:
namaBulan = "November"; break;
case 12:
namaBulan = "Desember"; break;
default:System.out.println("Tidak ada angka bulan untuk dikonversi");
}

tanggal.setText(hari+ " " + namaBulan + " " + nilai_tahun);
Njam.setText(jam+ " : " + menit+ " : " +detik);
//txtTglAnda.setDate(Date.valueOf(nilai_tahun + "-" + bulan + "-" + hari));
}
};




new javax.swing.Timer(1000, taskPerformer).start();
}

Category: Java | Added by: penta (2010-09-28)
Views: 673 | Tags: jam java, tanggal java, java, calendar | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *:
Search
Site friends
  • Create a free website
  • Copyright Penta.Inc © Powered By: Senjapala