SHARE
TWEET

Untitled

a guest Jun 17th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. long timestamp = 1245613885;
  2. Calendar calendar = Calendar.getInstance();
  3. calendar.setTimeZone(TimeZone.getDefault());
  4. calendar.setTimeInMillis(timestamp * 1000);
  5.  
  6. int year = calendar.get(Calendar.YEAR);
  7. int day = calendar.get(Calendar.DATE);
  8. int hour = calendar.get(Calendar.HOUR_OF_DAY);
  9. int minute = calendar.get(Calendar.MINUTE);
  10.      
  11. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  12. String dateString = sdf.format(calendar.getTime());
  13. System.out.println(dateString); // 2009-06-21 15:51:25
  14.      
  15. import java.util.Calendar;  
  16. import java.util.TimeZone;
  17.  
  18. public class Example{
  19.    public static void main(String[] args){
  20.       long utcTimestamp = 1285578547L;
  21.       Calendar cal = Calendar.getInstance(TimeZone.getDefault());
  22.       cal.setTimeInMillis(utcTimestamp * 1000);
  23.       System.out.println(cal.get(Calendar.YEAR));
  24.       System.out.println(cal.get(Calendar.MONTH));
  25.       System.out.println(cal.get(Calendar.DAY_OF_MONTH));
  26.       System.out.println(cal.get(Calendar.DAY_OF_YEAR));
  27.       System.out.println(cal.get(Calendar.HOUR));
  28.       System.out.println(cal.get(Calendar.MINUTE));
  29.    }
  30. }
  31.      
  32. Instant instant = Instant.ofEpochMilli( 1_245_613_885L ) ;
  33.      
  34. String output = instant.toString() ;
  35.      
  36. ZoneId z = ZoneId.of( "Australia/Sydney" ) ;
  37. ZonedDateTime zdt = instant.atZone( z ) ;  // Same moment as the `instant`, but different wall-clock time.
  38.      
  39. String output = zdt.toString() ;
  40.      
  41. Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"), Locale.US);
  42. calendar.setTimeInMillis(1245613885 * 1000);
  43. int year = calendar.get(Calendar.YEAR);
  44. int day = calendar.get(Calendar.DAY_OF_YEAR);
  45. int hour = calendar.get(Calendar.HOUR_OF_DAY);
  46. int minute = calendar.get(Calendar.MINUTE);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top