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

pha.java.util.TimeUtil Maven / Gradle / Ivy

package pha.java.util;

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


public class TimeUtil {
	
	public static long currSecond() {
		return System.currentTimeMillis() / 1000;
	}
	
	public static String currTime(String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(new Date());
	}
	
	public static String secToDate(long secs, String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(new Date(secs * 1000L));
	}
	
	public static long DateToSec(String date, String format) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			return sdf.parse(date).getTime() / 1000;
		} catch (Exception e) {
		}

		return -1;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy