Читать книгу Java Code - Алексей Алексеевич Крючков - Страница 10

Определение даты и дня недели

Оглавление

String dateToDay(String s){

        Calendar calendar=new GregorianCalendar();

        SimpleDateFormat sdf = new SimpleDateFormat(s);

         return sdf.format(calendar.getTime());

         }   

     String dayOfWeek(){

         Calendar calendar = Calendar.getInstance();

         String s="";

         switch(calendar.get(Calendar.DAY_OF_WEEK)){

             case 1:

                 s="воскресенье";

                 break;

                 case 2:

                     s="понедельник";

                     break;

                     case 3:

                         s="вторник";

                         break;

                         case 4:

                             s="среда";

                             break;

                             case 5:

                                 s="четверг";

                                 break;

                                 case 6:

                                     s="пятница";

                                     break;

                                     case 7:

                                         s="суббота";

                                         break;

                                         default:

                                             break;

         }

         return s;

     }


Java Code

Подняться наверх