How To Convert Local Fourth Dimension To Gmt Inwards Coffee - Illustration Tutorial

Converting local fourth dimension into GMT or whatever other timezone inward Java is slowly equally Java has back upwardly for fourth dimension zones. JDK has a course of pedagogy called java.util.Timezone which represents timezone too Java likewise has classes similar SimpleDateFormat which tin role Time zone spell parsing or formatting dates. By using java.uti.TimeZone too java.text.SimpleDateFormat nosotros tin write elementary Java programme to convert local fourth dimension to GMT or whatever other fourth dimension zone inward Java. We bring already seen event of How to larn electrical flow engagement too fourth dimension inward GMT too this Java programme is extension of that inward gild to convert fourth dimension shape 1 timezone to other timezone.

This article is inward continuation of my previous basic Java tutorials similar How to convert Double to String inward Java , How to convert char to String inward Java too how to write hashcode inward Java. If you lot haven’t read them already you lot may uncovering them useful.


Java programme to convert local fourth dimension to GMT or other Timezone

 or whatever other timezone inward Java is slowly equally Java has back upwardly for fourth dimension zones How to Convert Local Time to GMT inward Java - Example Tutorial
Here is consummate code event of converting local fourth dimension into GMT timezone. As I said you lot tin convert local fourth dimension to whatever other timezone yesteryear only setting electrical flow timezone for SimpleDateFormat equally shown inward this example. By the means beware spell using SimpleDateFormat in multi-threading surroundings equally SimpleDateFormat inward Java is non thread safe.


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * Simple Java programme to convert local fourth dimension into GMT or whatever other TimeZone inward Java
 * SimpleDateFormat inward Java tin locomote used to convert Date from 1 timezone to other
 * @author Javin
 */

public class TimeZoneConverter {

    public static void main(String args[]) {
   
     //Date volition supply local fourth dimension inward Java  
     Date localTime = new Date();
   
     //creating DateFormat for converting fourth dimension from local timezone to GMT
     DateFormat converter = new SimpleDateFormat("dd/MM/yyyy:HH:mm:ss");
   
     //getting GMT timezone, you lot tin larn whatever timezone e.g. UTC
     converter.setTimeZone(TimeZone.getTimeZone("GMT"));
   
     System.out.println("local fourth dimension : " + localTime);;
     System.out.println("time inward GMT : " + converter.format(localTime));
   
    }  
 
}

Output:
local fourth dimension : quarta-feira April 11 05:48:16 VET 2012
fourth dimension inward GMT : 11/04/2012:10:18:16



That's all on how to convert local fourth dimension into GMT or whatever other timezone inward Java similar UTC or EDT etc. spell converting fourth dimension shape 1 timezone to to a greater extent than or less other only continue an oculus on 24-hour interval lite saving equally to a greater extent than or less Timezone falls nether 24-hour interval lite fourth dimension saving zone.

Further Learning
Complete Java Masterclass
Difference betwixt outset too run method of Thread inward Java

0 Response to "How To Convert Local Fourth Dimension To Gmt Inwards Coffee - Illustration Tutorial"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel