When we talk about Time without timezone's it makes no sense, "Time is relative" so it's very important to know either the timezone or the offset of time from GMT/UTC in order to understand which part of the world the time belongs to. If you want to display time as an offset in Java programming you need to make use of the Date object and the DateFormat object, let us see how this can be achieved,
Code Example: Java Date with GMT/UTC Offset using SimpleDateFormat:
public static void main(String[] args) {
Date myDate = new Date();
DateFormat dateFormatWithOffset = new SimpleDateFormat("dd-MM-yyyy HH:mm Z");
System.out.println("Current Time with Offset: " + dateFormatWithOffset.format(myDate));
}
Output: Current Time with Offset: 26-03-2021 10:00 -0500
As you can see in the above example, we created a Java date object using java.util.Date package, and DateFormat object using java.text.SimpleDateFormat package. Note that Z in the SimpleDateFormat string displays the timezone - the offset in ISO 8601 time zone format. -0500 is the offset of timezone America/Chicago

- How to get Java Thread name Example [Program]
- Java 8: Get First and Last Date of the Week for Given Date
- Convert String to int in Java
- How to Get List of All Country Codes in Java Using Locale Class
- Convert Multidimensional Array toString In Java
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Create a Zip file using Java Code programmatically
- [Fix] java.net.MalformedURLException: unknown protocol
- [fix] Java JDBC ConnectException: Connection refused
- Read Json File and Convert to Java Object using Jackson
- list of jars required for hibernate 4.x.x
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java: The value of the local variable string is not used
- [fix] URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs) IntelliJ
- Java 8+ get Day of the Week Examples with LocalDateTime, DateTime, ZonalDateTime and Instant classes
- Run SQL Script file using Java JDBC Code Example
- Remove Trailing zeros BigDecimal Java
- Java JDBC IN Clause Example with PreparedStatement MySQL
- Convert Java List to Json String using Jackson
- Java 8 foreach loop code examples
- error: file not found: HelloWorld.java
- IntelliJ Keyboard Shortcut to remove unused imports [Java]
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Struts 2 Hello World Example in Eclipse
- Android Toolbar example with appcompat_v7 21 - Android
- SharePoint Server 2016 IT Preview Deprecated Removed features - SharePoint
- Get-ADUser PowerShell - Get AD user details using email address - SharePoint
- [Android Studio] Hardcoded string Button, should use @string resource - Android-Studio
- Remove duplicate lines using Notepad++ - NotepadPlusPlus
- HTML5 HELLO WORLD Example - Html
- Facebook Down Will Be Back Soon - Facebook
- Notepad++ select all above or below lines - NotepadPlusPlus