Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 16, 2020 21:48
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 parzibyte/dc8f27f247c7339926355ce6f3002f07 to your computer and use it in GitHub Desktop.
Save parzibyte/dc8f27f247c7339926355ce6f3002f07 to your computer and use it in GitHub Desktop.
class Utiles {
public static String obtenerHoraActual(String zonaHoraria) {
String formato = "HH:mm:ss";
return Utiles.obtenerFechaConFormato(formato, zonaHoraria);
}
public static String obtenerFechaActual(String zonaHoraria) {
String formato = "yyyy-MM-dd";
return Utiles.obtenerFechaConFormato(formato, zonaHoraria);
}
@SuppressLint("SimpleDateFormat")
public static String obtenerFechaConFormato(String formato, String zonaHoraria) {
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat(formato);
sdf.setTimeZone(TimeZone.getTimeZone(zonaHoraria));
return sdf.format(date);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment