Java XML Date Create toDate(long date)

Here you can find the source of toDate(long date)

Description

to Date

License

MIT License

Declaration

public static Date toDate(long date) 

Method Source Code

//package com.java2s;
/*!/* ww  w.j av a2  s  . c o  m*/
 * mifmi-commons4j
 * https://github.com/mifmi/mifmi-commons4j
 *
 * Copyright (c) 2015 mifmi.org and other contributors
 * Released under the MIT license
 * https://opensource.org/licenses/MIT
 */

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import java.util.Locale;

import java.util.TimeZone;

import javax.xml.datatype.XMLGregorianCalendar;

public class Main {
    public static Date toDate(long date) {
        return new Date(date);
    }

    public static Date toDate(java.sql.Date date) {
        if (date == null) {
            return null;
        }
        return new Date(date.getTime());
    }

    public static Date toDate(java.sql.Time time) {
        if (time == null) {
            return null;
        }
        return new Date(time.getTime());
    }

    public static Date toDate(java.sql.Timestamp timestamp) {
        if (timestamp == null) {
            return null;
        }
        return new Date(timestamp.getTime());
    }

    public static Date toDate(Calendar calendar) {
        if (calendar == null) {
            return null;
        }
        return calendar.getTime();
    }

    public static Date toDate(XMLGregorianCalendar calendar) {
        if (calendar == null) {
            return null;
        }
        return calendar.toGregorianCalendar().getTime();
    }

    public static GregorianCalendar toGregorianCalendar(Date date) {
        return toGregorianCalendar(date, null, null);
    }

    public static GregorianCalendar toGregorianCalendar(Date date, TimeZone timeZone, Locale locale) {
        if (date == null) {
            return null;
        }
        return toGregorianCalendar(date.getTime(), timeZone, locale);
    }

    public static GregorianCalendar toGregorianCalendar(long date) {
        return toGregorianCalendar(date, null, null);
    }

    public static GregorianCalendar toGregorianCalendar(long date, TimeZone timeZone, Locale locale) {
        GregorianCalendar gccal = getGregorianCalendar(timeZone, locale);
        gccal.setTimeInMillis(date);
        return gccal;
    }

    public static GregorianCalendar getGregorianCalendar(TimeZone timeZone, Locale locale) {
        GregorianCalendar gcal;
        if (timeZone == null) {
            if (locale == null) {
                gcal = new GregorianCalendar();
            } else {
                gcal = new GregorianCalendar(locale);
            }
        } else {
            if (locale == null) {
                gcal = new GregorianCalendar(timeZone);
            } else {
                gcal = new GregorianCalendar(timeZone, locale);
            }
        }
        return gcal;
    }
}

Related

  1. getXMLGregorianCalendarFromDate(Date date)
  2. getXMLGregorianCalendarFromDate(Date date)
  3. getXMLGregorianCalendarValue( Date date)
  4. getXMLGregorianCalenderDate()
  5. toDate(final XMLGregorianCalendar xml)
  6. toDate(XMLGregorianCalendar cal)
  7. toDate(XMLGregorianCalendar cal)
  8. toDate(XMLGregorianCalendar date)
  9. toDate(XMLGregorianCalendar dateTime)