Advertisement
Manavard

Untitled

May 31st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. package date_time_and_other;
  2.  
  3. import java.time.*;
  4. import java.time.format.DateTimeFormatter;
  5. import java.time.format.FormatStyle;
  6. import java.time.temporal.ChronoUnit;
  7. import java.util.*;
  8. import java.util.Scanner;
  9. import java.lang.String;
  10.  
  11.  
  12. public class Date_Time {
  13. public static void main(String[] args) {
  14.  
  15. try {
  16.  
  17. System.out.println("Выберете язык: \n en - EN\n eu - RU \n uz - UZ\n");
  18.  
  19. Scanner in = new Scanner(System.in);
  20. String num = in.next();
  21.  
  22.  
  23. // Русский
  24. Locale.setDefault(new Locale(num, num));
  25. System.out.println("Вы выбрали " + Locale.getDefault());
  26. ResourceBundle myBundle = ResourceBundle.getBundle("MyLabels");
  27.  
  28.  
  29. //Узбекский
  30. //Locale.setDefault(new Locale("uz", "UZ"));
  31. //System.out.println("Siz o'zbek tilini tanladingiz: " + Locale.getDefault());
  32. //myBundle = ResourceBundle.getBundle("MyLabels_uz_UZ");
  33.  
  34.  
  35. // Английский
  36. //Locale.setDefault(new Locale("en", "EN"));
  37. //System.out.println("You have chosen English: " + Locale.getDefault());
  38. //yBundle = ResourceBundle.getBundle("MyLabels_en_EN");
  39.  
  40.  
  41. long milSecondFromEpoch = Instant.ofEpochMilli(0L).until(Instant.now(), ChronoUnit.MILLIS);
  42. int daysFromEpoch = (int) (milSecondFromEpoch / 86400000);
  43. int yearsFromEpoch = daysFromEpoch / 365;
  44. Instant UTStart = Instant.ofEpochMilli(milSecondFromEpoch - milSecondFromEpoch);
  45. ZonedDateTime ZUTStart = UTStart.atZone(ZoneId.of("Asia/Tashkent"));
  46.  
  47. System.out.println(ZonedDateTime.now().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL)) + " " + myBundle.getString("date"));//" - Текущая дата и время.");
  48. System.out.print(milSecondFromEpoch + " " + myBundle.getString("milisec") + " ");//" - милисекунд или ");
  49. System.out.print(daysFromEpoch + " " + myBundle.getString("days") + " "); //+ " - дней, или ");
  50. System.out.println(yearsFromEpoch + " " + myBundle.getString("years") /*" - лет, прошло с "*/ + " " + (ZUTStart.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL))) + " " + myBundle.getString("moment"));//", момента запуска Unix time");
  51.  
  52.  
  53. Scanner ini = new Scanner(System.in);
  54. System.out.println(myBundle.getString("insert_the_number"));//"Введите число:");
  55. long nums = ini.nextLong();
  56. Instant dt = Instant.ofEpochMilli(nums);
  57. ZonedDateTime zdt = dt.atZone(ZoneId.of("Asia/Tashkent"));
  58. System.out.println(zdt.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL)));
  59.  
  60.  
  61. long daysBetween = ChronoUnit.DAYS.between(UTStart, dt);
  62. //double weeksBetween = daysBetween/7;
  63. System.out.println(daysBetween + " " + myBundle.getString("since"));//" день с момента запуска Unix time.");
  64. //System.out.println(weeksBetween + " недель про...");
  65.  
  66. System.out.println(myBundle.getString("bye"));
  67.  
  68. } catch (MissingResourceException exc) {
  69. System.out.println("Вы ввели недопустимое значение.");
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement