Java Calender and Date

By | October 25th 2019 08:53:41 PM | viewed 45 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 : 9222

Today :7

Today Visit Country :

  • United States