How to Convert a Date to UTC Using Java

Written by mike heldar
  • Share
  • Tweet
  • Share
  • Email

The Universal Time Clock (UTC) is a standardised format for date storage that can be read from the Java framework. UTC is based on an absolute date: January 1, 1970 in Greenwich Mean Time. Java lets you convert times into UTC using a few simple commands in your program.

Skill level:
Moderately Easy

Other People Are Reading

Things you need

  • Java program with a date or time stamp

Show MoreHide


  1. 1

    Acquire a date value of the current local time. If one is not present, you can set one using the Calendar object's set parameter. For example, to set the time to nine p.m. on April 20, 2011:

    Calendar test = new test Calendar();

    test.set(Calendar.HOUR_OF_DAY, 21);

    test.set(Calendar.MINUTE, 30);

    test.set(Calendar.SECOND, 0);

  2. 2

    Convert the time zone of the test calendar object to GMT:


  3. 3

    Retrieve the current time of day from the Java calendar in UTC format:

    $variable = test.get(Calendar.HOUR_OF_DAY);

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.