All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nz.net.osnz.common.utils.DateUtils.groovy Maven / Gradle / Ivy

The newest version!
package nz.net.osnz.common.utils

import org.joda.time.DateTime

/**
 * Created by kdeng on 15/03/14.
 */
public class DateUtils {

    public static final String DATETIME_FORMAT = 'yyyy-mm-dd HH:mm:ss'

    public static final String DATE_FORMAT = 'yyyy-mm-dd'

    public static final String TIME_FORMAT = 'HH:mm:ss'

    /**
     * this class is not instantiable
     */
    private DateUtils() {}

    /**
     * format DateTime Section
     */
    public static String renderDateTime(Date date) {
        return date.format(DATETIME_FORMAT)
    }

    public static String renderDateTime(DateTime dateTime) {
        return renderDateTime(dateTime.toDate())
    }

    public static String renderDateTime(long timestamp) {
        return renderDateTime(new Date(timestamp))
    }

    /**
     * format Date Section
     */
    public static String renderDate(Date date) {
        return date.format(DATE_FORMAT)
    }

    public static String renderDate(DateTime dateTime) {
        return renderDate(dateTime.toDate())
    }

    public static String renderDate(long timestamp) {
        return renderDate(new Date(timestamp));
    }

    /**
     * format Time Section
     */
    public static String renderTime(Date date) {
        return date.format(TIME_FORMAT)
    }

    public static String renderTime(DateTime dateTime) {
        return renderTime(dateTime.toDate())
    }

    public static String renderTime(long timestamp) {
        return renderTime(new Date(timestamp))
    }

    /**
     * get current date time
     */
    public static String getCurrentDatetime() {
        return renderDateTime(new Date())
    }

    public static String getCurrentDate() {
        return renderDate(new Date())
    }

    public static String getCurrentTime() {
        return renderTime(new Date())
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy