[Java] Hiển thị ngày và thời gian hiện tại

Để hiện thị ngày tháng và thời gian hiện tại của hệ thống chỉ cần khai báo thư viện
// get current date and time
java.util.Date date=new java.util.Date();


Code Java: Hiển thị ngày, thời gian hiện tại dưới dạng đồng hồ số

/******************************************************************************
* File : SimpleClock.java
* Author : http://lap-trinh-may-tinh.blogspot.com/
* Description :
* Display a digital clock
* Tested with : JDK 1.6
******************************************************************************/

import javax.swing.JLabel;
public class SimpleClock {

public static void main(String[] args) throws Exception
{

// create a image label
JLabel label=new JLabel("", JLabel.CENTER);
label.setPreferredSize(new java.awt.Dimension(300,200));

// create frame
javax.swing.JFrame frame=new javax.swing.JFrame();
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setTitle("Macteki SimpleClock");
frame.add(label); // add the imageLabel to the frame
frame.pack(); // set the window size to the size of the component (imageLabel)
frame.setVisible(true);
while (true)
  {
   Thread.sleep(500);
   java.util.Date date=new java.util.Date();
   label.setText(""+date);
  }
 }
}

Một số tài liệu và khoá học bổ ích dành cho bạn: 

# Tài liệu: Lập trình hướng đối tượng JAVA core dành cho người mới bắt đầu học lập trình [Click để xem]

# Khoá học online: Lập trình Java trong 4 tuần [Click để xem]

Tìm kiếm nội dung khác: