Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. Calendar c = Calendar.getInstance();
  2. int seconds = c.get(Calendar.SECOND);
  3.  
  4. Time now = new Time();
  5. now.setToNow();
  6.  
  7. Time time = new Time(); time.setToNow();
  8. Log.d("TIME TEST", Long.toString(time.toMillis(false)));
  9. ... do something that takes more than one millisecond, but less than one second ...
  10.  
  11. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
  12. String currentDateandTime = sdf.format(new Date());
  13.  
  14. Time today = new Time(Time.getCurrentTimezone());
  15. today.setToNow();
  16.  
  17. textViewDay.setText(today.monthDay + ""); // Day of the month (1-31)
  18. textViewMonth.setText(today.month + ""); // Month (0-11)
  19. textViewYear.setText(today.year + ""); // Year
  20. textViewTime.setText(today.format("%k:%M:%S")); // Current time
  21.  
  22. DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy, HH:mm");
  23. String date = df.format(Calendar.getInstance().getTime());
  24.  
  25. "yyyy.MM.dd G 'at' HH:mm:ss z" ---- 2001.07.04 AD at 12:08:56 PDT
  26. "hh 'o''clock' a, zzzz" ----------- 12 o'clock PM, Pacific Daylight Time
  27. "EEE, d MMM yyyy HH:mm:ss Z"------- Wed, 4 Jul 2001 12:08:56 -0700
  28. "yyyy-MM-dd'T'HH:mm:ss.SSSZ"------- 2001-07-04T12:08:56.235-0700
  29. "yyMMddHHmmssZ"-------------------- 010704120856-0700
  30. "K:mm a, z" ----------------------- 0:08 PM, PDT
  31. "h:mm a" -------------------------- 12:08 PM
  32. "EEE, MMM d, ''yy" ---------------- Wed, Jul 4, '01
  33.  
  34. String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
  35.  
  36. Feb 27, 2012 5:41:23 PM
  37.  
  38. Date currentDate = new Date(System.currentTimeMillis());
  39.  
  40. Time currentTime = new Time();
  41. currentTime.setToNow();
  42.  
  43. Calendar cal = Calendar.getInstance();
  44.  
  45. int millisecond = cal.get(Calendar.MILLISECOND);
  46. int second = cal.get(Calendar.SECOND);
  47. int minute = cal.get(Calendar.MINUTE);
  48. //12 hour format
  49. int hour = cal.get(Calendar.HOUR);
  50. //24 hour format
  51. int hourofday = cal.get(Calendar.HOUR_OF_DAY);
  52.  
  53. Calendar cal = Calendar.getInstance();
  54.  
  55. int dayofyear = cal.get(Calendar.DAY_OF_YEAR);
  56. int year = cal.get(Calendar.YEAR);
  57. int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
  58. int dayofmonth = cal.get(Calendar.DAY_OF_MONTH);
  59.  
  60. String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
  61.  
  62. // textView is the TextView view that should display it
  63. textView.setText(currentDateTimeString);
  64.  
  65. Calendar c = Calendar.getInstance();
  66. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  67. String strDate = sdf.format(c.getTime());
  68.  
  69. 2014-11-11 00:47:55
  70.  
  71. final Calendar c = Calendar.getInstance();
  72. int mYear = c.get(Calendar.YEAR);
  73. int mMonth = c.get(Calendar.MONTH);
  74. int mDay = c.get(Calendar.DAY_OF_MONTH);
  75.  
  76. textView.setText(""+mDay+"-"+mMonth+"-"+mYear);
  77.  
  78. Time time = new Time();
  79. time.setToNow();
  80. System.out.println("time: " + time.hour+":"+time.minute);
  81.  
  82. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  83. Calendar cal = Calendar.getInstance();
  84. System.out.println("time => " + dateFormat.format(cal.getTime()));
  85.  
  86. String time_str = dateFormat.format(cal.getTime());
  87.  
  88. String[] s = time_str.split(" ");
  89.  
  90. for (int i = 0; i < s.length; i++) {
  91. System.out.println("date => " + s[i]);
  92. }
  93.  
  94. int year_sys = Integer.parseInt(s[0].split("/")[0]);
  95. int month_sys = Integer.parseInt(s[0].split("/")[1]);
  96. int day_sys = Integer.parseInt(s[0].split("/")[2]);
  97.  
  98. int hour_sys = Integer.parseInt(s[1].split(":")[0]);
  99. int min_sys = Integer.parseInt(s[1].split(":")[1]);
  100.  
  101. System.out.println("year_sys => " + year_sys);
  102. System.out.println("month_sys => " + month_sys);
  103. System.out.println("day_sys => " + day_sys);
  104.  
  105. System.out.println("hour_sys => " + hour_sys);
  106. System.out.println("min_sys => " + min_sys);
  107.  
  108. Time now = new Time();
  109. now.setToNow();
  110.  
  111. Time t = new Time(Time.getCurrentTimezone());
  112. t.setToNow();
  113. String date = t.format("%Y/%m/%d");
  114.  
  115. Date todayDate = new Date();
  116. todayDate.getDay();
  117. todayDate.getHours();
  118. todayDate.getMinutes();
  119. todayDate.getMonth();
  120. todayDate.getTime();
  121.  
  122. SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ",Locale.ENGLISH);
  123. String cDateTime=dateFormat.format(new Date());
  124.  
  125. String Datetime;
  126. Calendar c = Calendar.getInstance();
  127. SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss aa");
  128. Datetime = dateformat.format(c.getTime());
  129. System.out.println(Datetime);
  130.  
  131. Calendar cal = Calendar.getInstance();
  132.  
  133. String date = ""+cal.get(Calendar.DATE)+"-"+(cal.get(Calendar.MONTH)+1)+"-"+cal.get(Calendar.YEAR);
  134.  
  135. String time = ""+cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement