SimpleDateFormat(“HH:mm:ss Z”) 在 Java 中
Z 指“零小时偏移”,在 ISO 8601 时间表示法中也称为“祖鲁时间”(UTC)。然而,ACP 121 标准定义了军用时区列表,并从格林尼治标准时间 (GMT) 得出“祖鲁时间”。
让我们来看看 SimpleDateFormat(“HH:mm:ss Z”) 的用法 −
Format f = new SimpleDateFormat("HH.mm.ss Z"); String strResult = f.format(new Date()); System.out.println("Time = "+strResult);
以下是完整示例,显示带偏移量 (HH:mm:ss Z) 的时间 −
示例
import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); System.out.println("Today's date = "+simpleformat.format(cal.getTime())); // current time Format f = new SimpleDateFormat("HH.mm.ss Z"); String strResult = f.format(new Date()); System.out.println("Time = "+strResult); // displaying hour f = new SimpleDateFormat("H"); String strHour = f.format(new Date()); System.out.println("Current Hour = "+strHour); // displaying minutes f = new SimpleDateFormat("mm"); String strMinute = f.format(new Date()); System.out.println("Current Minutes = "+strMinute); // displaying seconds f = new SimpleDateFormat("ss"); String strSeconds = f.format(new Date()); System.out.println("Current Seconds = "+strSeconds); } }
输出
Today's date = 26/November/2018 08:52:33 Time = 08.52.33 +0000 Current Hour = 8 Current Minutes = 52 Current Seconds = 33
广告