Format hour in HH (00-23) format like 00, 01..23 in Java

Description

The following code shows how to format hour in HH (00-23) format like 00, 01..23.

Example


/* w  w w  .  j  a v  a 2s  .  c om*/
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

  public static void main(String[] args) {
    Date date = new Date();
    
    
    SimpleDateFormat sdf = new SimpleDateFormat("HH");
    System.out.println("hour in HH format : " + sdf.format(date));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone