Last active
August 29, 2015 14:05
-
-
Save felipeska/6c51954de178fbd21406 to your computer and use it in GitHub Desktop.
obtain the time based on the time zone in Java...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.GregorianCalendar; | |
import java.util.Locale; | |
import java.util.Calendar; | |
import org.joda.time.DateTime; | |
import org.joda.time.format.DateTimeFormat; | |
import org.joda.time.format.DateTimeFormatter; | |
public static class TimeUtils { | |
public static String getDatePhone() { | |
final String dateFormat = "yyyy-MM-dd"; | |
Calendar cal = new GregorianCalendar(); | |
Date date = cal.getTime(); | |
SimpleDateFormat df = new SimpleDateFormat(dateFormat, Locale.getDefault()); | |
String formatteDate = df.format(date); | |
return formatteDate; | |
} | |
public static String getHourPhone() { | |
final String hourFormat = "HH:mm:ss"; | |
Date dt = new Date(); | |
SimpleDateFormat df = new SimpleDateFormat(hourFormat, | |
Locale.getDefault()); | |
String formatteHour = df.format(dt.getTime()); | |
return formatteHour; | |
} | |
public static long getLongDate() { | |
final String UNIX_PATTERN_DATE = "yyyy-MM-dd HH:mm:ss"; | |
DateTime date; | |
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern( | |
UNIX_PATTERN_DATE).withZoneUTC(); | |
date = dateTimeFormatter.parseDateTime(getDatePhone() + " " | |
+ getHourPhone()); | |
return date.getMillis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment