关于Unix时间戳转北京时间的问题

工具在这里:http://tool.chinaz.com/Tools/unixtime.aspx?qq-pf-to=pcqq.group

今天踩了坑,无论参数是多少,年份总是1970。才发现原来参数必须是long不能是int

    /*
     * 输入参数long类型的time,返回格式为yyyy-MM-dd HH:mm:ss的时间
     */
    public static String switchIntToDate(long time) {
        String pattern = "yyyy-MM-dd HH:mm:ss";
        String result = null;  
        Date date = new Date(time*1000);  
        SimpleDateFormat sd = new SimpleDateFormat(pattern);  
        result = sd.format(date);  
        return result;  
    }

    /*
     * 测试
     */
    public static void main(String[] args) {
        System.out.println(getCurrentYearAndMonth(0));
        System.out.println(switchIntToDate(1509678698));
    }
原文地址:https://www.cnblogs.com/XJJD/p/7777263.html