Saturday, May 11, 2013

Date to get Day

import java.text.SimpleDateFormat;
import java.util.Date;

public class GetDateMethod {
  public static void main(String[] args) {
        Date obDate = new Date();
        SimpleDateFormat obDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("Current Date of system :"
                + obDateFormat.format(obDate.getTime()));
        System.out.println("Day of given date : " + obDate.getDay());
    }
}


Output
Current Date of system :2010-11-25 04:11:25 PM
Hours of given date : 4

---------------------------------
// da-getDay1.jsl
// Date.getDay example

import java.util.*;

public class MyClass
{
    public static void main(String[] args)
    {
        // Construct a date object:
        Date d = new Date("11-Dec-1314");

        // Get the day number:
        System.out.println("Date part in 11-Dec-1314 is: " +
            d.getDay());
    }
}

/*
Output:
Date part in 11-Dec-1314 is: 11
*/

Set Date into Textbox with DateFormat


public FrmDate() {    //Constructor
    initWidget(uiBinder.createAndBindUi(this));
     .
     .
    setDateFormat();
    dbFrom.setValue(new Date());
    dbTo.setValue(new Date());
     .
}

private void setDateFormat() {
   dbFrom.setFormat(new DateBox.DefaultFormat (DateTimeFormat.getFormat("dd/MM/yyyy")));
   dbTo.setFormat(new DateBox.DefaultFormat (DateTimeFormat.getFormat("dd/MM/yyyy")));
}


Get DateBox to Objece


String fromDate="";
String toDate="";
if(dbFrom.getValue()!=null || dbTo.getValue()!=null)
{
        Date fDate = dbFrom.getValue();
        Date tDate = dbTo.getValue();

        DateTimeFormat fmt = DateTimeFormat.getFormat("yyyyMMdd");
        fromDate =fmt.format(fDate);
        toDate = fmt.format(tDate);
}

String Date to DateBox

@UiField DateBox dbTo;
@UiField DateBox dbFrom;

String fromDate = formatMIT2DDMMYYYY(p_result.getHeaderDataList().get(i).getT4()) ;
String toDate =formatMIT2DDMMYYYY(p_result.getHeaderDataList().get(i).getT5()) ;

Date d1 = new DateBox.DefaultFormat(DateTimeFormat.getFormat("dd/MM/yyyy")).parse(dbFrom, fromDate , false );
dbFrom.setValue(d1) ;


Date d2 = new DateBox.DefaultFormat(DateTimeFormat.getFormat("dd/MM/yyyy")).parse(dbFrom, toDate , false );
dbTo.setValue(d2) ;


public static String formatMIT2DDMMYYYY(String p) {
        String ret="";
        try{
           int y = Integer.parseInt(   p.substring(0, 4)  );    
           int m = Integer.parseInt(   p.substring(4, 6)  );           
           int d = Integer.parseInt(   p.substring(6, 8)  );
           ret = d + "/" + m + "/" + y ;
           ret = p.substring(6, 8)+"/" + p.substring(4, 6)+"/"+ p.substring(0, 4);
        } catch (Exception ex){}
        return ret;
}