Java Calender and Date

By ukmodak | March 31st 2024 10:34:01 AM | viewed 252 times

Java Calender date

 Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());

        //cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));   monthly first date
        //return cal.getTime();

        //int totalWeekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);
        //int firstDayOfMonth = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        //int lastDayOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        int currentDayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
        // int dayofWeek = cal.get(Calendar.DAY_OF_WEEK);
        int weekNo ;
        def hrTlShiftId


        if(currentDayOfMonth >=1 && currentDayOfMonth <=7){
            weekNo = 1;
        }else if(currentDayOfMonth >=8 && currentDayOfMonth <=14){
            weekNo = 2;
        }else if(currentDayOfMonth >=15 && currentDayOfMonth <=21){
            weekNo = 3;
        }else if(currentDayOfMonth >=22 && currentDayOfMonth <=28){
            weekNo = 4;
        }else if(currentDayOfMonth >=29 && currentDayOfMonth <=31){
            weekNo = 5;
        }

String to Date Oject in Java

SimpleDateFormat ymdFmt = new java.text.SimpleDateFormat("yyyy-MM-dd")
String receive = ymdFmt.format(new Date())                                                // for auto date creation
SimpleDateFormat dateTimeFormat = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  // 12 hours
SimpleDateFormat receiveDate = dateTimeFormat.parse("${receive} 00:00:00");
SimpleDateFormat ymdFmt = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")   
String receive = ymdFmt.format(new Date())                                               // for auto date creation
SimpleDateFormat dateTimeFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // HH 24 hours
SimpleDateFormat receiveDate = dateTimeFormat.parse("${receive} HH:mm:ss");

String dateAndTime ="MM-dd-yyyy";
SimpleDateFormat df = new java.text.SimpleDateFormat("MM-dd-yyyy");   
java.util.Date fromDate = df.parse(dateAndTime);

String dateAndTime ="dd/MM/yyyy";
SimpleDateFormat df = new java.text.SimpleDateFormat("dd/MM/yyyy");   
java.util.Date fromDate = df.parse(dateAndTime);

bONEandALL
Visitor

Total : 20975

Today :29

Today Visit Country :

  • Germany
  • United States
  • Singapore
  • China
  • United Kingdom
  • South Korea
  • Czechia