How to get system system time through Java?
Date now= new date (); SimpleDateFormat DateFormat=new simpledateformat ("Yyyy-mm-dd HH:mm:ss. Sssssssss "); String nowformate= Dateformat.format (now); System.out.println (nowformate);
Output results
2017-02-16 20:56:12.000000278
How to get the current system is the week?
Method One,
String weekofday= Getweekofday (now); System.out.println (weekofday); Public Static String getweekofday (date date) { string[] weekdays=new string[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday" , "Friday", "Saturday"}; Calendar Calendar= calendar.getinstance (); Calendar.settime (date); int weekindex= calendar.get (Calendar.day_of_week)-1; if (weekindex<0) weekindex=0; return Weekdays[weekindex]; }
Method Two,
SimpleDateFormat dateformat2=new SimpleDateFormat ("eeee"); String nowFormate2= Dateformat2.format (now); System.out.println (NOWFORMATE2);
Calendar gets the year, month, day of the current system date
Calendar calendar= calendar.getinstance (); Calendar.settime (now); int year= calendar.get (calendar.year); int month= calendar.get (calendar.month) +1; int day= calendar.get (calendar.day_of_month); System.out.println (year + "-" +month+ "-" +day ");
Java: Date class dates and calendar