Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String StampToString(long stamp) {
        /*
         String[] formats = new String[] {  
         "yyyy-MM-dd",   
         "yyyy-MM-dd HH:mm",  
         "yyyy-MM-dd HH:mmZ",   
         "yyyy-MM-dd HH:mm:ss.SSSZ",
         "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
         }; 
         */
        Date date = null;
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(stamp);
        date = calendar.getTime();

        //       String format = "yyyy-MM-dd HH:mm:ss.SSSZ"; 
        String format = "yyyy-MM-dd HH:mm:ss.SSSZ";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        //sdf.setTimeZone(TimeZone.getTimeZone("UTC"));   
        sdf.setTimeZone(TimeZone.getTimeZone("PRC"));

        return sdf.format(date);

    }
}