Skip to content

Instantly share code, notes, and snippets.

@lseongjoo
Last active December 12, 2015 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lseongjoo/4689833 to your computer and use it in GitHub Desktop.
Save lseongjoo/4689833 to your computer and use it in GitHub Desktop.
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TimeUtil {
public static Timestamp getTimestamp(){
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
return timestamp;
}
public static String getTimestamp(String pattern){
if(pattern.isEmpty()){
pattern = "yyyy-MM-dd HH:mm:ss";
}
SimpleDateFormat dateformat = new SimpleDateFormat(pattern, Locale.KOREA);
Timestamp timestamp = getTimestamp();
String time = dateformat.format(timestamp);
return time;
}
public static long getTimestamp(Timestamp timestamp){
return timestamp.getTime();
}
public static String getTimeFormat(long time){
Date date = new Date(time);
SimpleDateFormat dateFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.KOREA);
return dateFormat.format(date);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment