Some Methods to find days and Dates

-----------------------------------------------------------------------------------------------------------

Method To get month Name on passing month number

-----------------------------------------------------------------------------------------------------------

def getMonth(int month) {

   return new DateFormatSymbols().getMonths()[month-1];

}

---------------------------------------------------------------------------------

Method to get Number of Days in a Month

----------------------------------------------------------------------------------

def daysInAMonth(){

int iYear = year

int iMonth = month

int iDay = 1;

getDates(iMonth,iYear)

// Create a calendar object and set year and month

Calendar mycal = new GregorianCalendar(iYear, iMonth-1, iDay);

// Get the number of days in that month

def daysInMonth = mycal.getActualMaximum(Calendar.DAY_OF_MONTH)

def daysMap=[:]

daysMap.put("days",daysInMonth)

render daysMap as JSON

}

------------------------------------------------------------------------------------

Another easy way To calculate days in a month

------------------------------------------------------------------------------------

public static int daysInMonth(GregorianCalendar c) {

   int [] daysInMonths = {31,28,31,30,31,30,31,31,30,31,30,31};

   daysInMonths[1] += c.isLeapYear(c.get(GregorianCalendar.YEAR)) ? 1 : 0;

   return daysInMonths[c.get(GregorianCalendar.MONTH)];

 }

--------------------------------------------------------------------------------------

Method To calculate sundays in a month

--------------------------------------------------------------------------------------

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Sundays {

   public static void main(String[] args) {

      int year = 2012;

      // put the month you want

      int month = Calendar.JANUARY;

      Calendar cal = new GregorianCalendar(year, month, 1);

      do {

          int day = cal.get(Calendar.DAY_OF_WEEK);

          if (day == Calendar.SATURDAY || day == Calendar.SUNDAY) {

              System.out.println(cal.get(Calendar.DAY_OF_MONTH));

          }

          cal.add(Calendar.DAY_OF_YEAR, 1);

      }  while (cal.get(Calendar.MONTH) == month);

   }

}

-----------------------------------------------------------------------------------------

To get Day of a Month

-------------------------------------------------------------------------------------------

   Calendar cal = Calendar.getInstance();

   int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);

---------------------------------------------------------------------------------------------

Jquery to format number to 2 decimal places

-----------------------------------------------------------------------------------------------

$("#discount").change(function() {

var list = $("#list").val();

var discount = $("#discount").val();

var price = $("#price");

var temp = discount * list;

var temp1 = list - temp;

var total = temp1.toFixed(2);

price.val(total);

});






No comments:

Post a Comment