Java Date Create toDatetime(long value)

Here you can find the source of toDatetime(long value)

Description

to Datetime

License

Open Source License

Declaration

public static String toDatetime(long value) 

Method Source Code

//package com.java2s;
/**/*from   w w  w .  j ava2s.  c  om*/
 * Project: ${puma-server.aid}
 * 
 * File Created at 2012-6-11 $Id$
 * 
 * Copyright 2010 dianping.com. All rights reserved.
 * 
 * This software is the confidential and proprietary information of Dianping
 * Company. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with dianping.com.
 */

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

public class Main {
    public static String toDatetime(long value) {
        int sec = (int) (value % 100);
        if (value <= 1) {
            sec = 1;
        }
        value /= 100;
        int min = (int) (value % 100);
        value /= 100;
        int hour = (int) (value % 100);
        value /= 100;
        int day = (int) (value % 100);
        value /= 100;
        int mon = (int) (value % 100);
        int year = (int) (value / 100);
        if (mon > 0 && day > 0 && year > 0) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar c = Calendar.getInstance();
            c.set(year, mon - 1, day, hour, min, sec);
            return sdf.format(c.getTime());
        } else {
            return String.format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec);
        }
    }
}

Related

  1. toDateStr(Date d)
  2. ToDateStr(Date dt)
  3. toDateStr(Object o)
  4. toDateText(Date date)
  5. toDateTime(Date date)