convert Time With Time Zone - Java java.util

Java examples for java.util:Timezone

Description

convert Time With Time Zone

Demo Code


//package com.java2s;
import java.util.Calendar;
import java.util.TimeZone;

public class Main {
    public static void main(String[] argv) throws Exception {
        long time = 2;
        System.out.println(convertTimeWithTimeZome(time));
    }//  w w  w. j  a  va2s  .co  m

    /**
     * 
     * @param time
     * @return Current Date
     */
    public static String convertTimeWithTimeZome(long time) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));
        cal.setTimeInMillis(time);
        return (cal.get(Calendar.YEAR) + " "
                + (cal.get(Calendar.MONTH) + 1) + " " + cal
                    .get(Calendar.DAY_OF_MONTH));
    }
}

Related Tutorials