Is this Code Useful for you ?

Is this Posible

Is this Posible
Rack your brain 4 possibilities....

Friday, December 25, 2009

Date Class - validating Date, formatting ,getting current date ... etc

“No dream is bigger than the dreamer…….”



import java.util.Calendar;
import java.util.Date;
public class gDate {

public final int DATE_FORMAT_DD_MM_YY = 0 ;
public final int DATE_FORMAT_DD_MM_YYYY = 1 ;
public final int DATE_FORMAT_MM_DD_YYYY = 2 ;
public final int DATE_FORMAT_DDMMYYYY = 3 ;
public final int DATE_FORMAT_MMDDYYYY = 4 ;
private int format = 0;
private String sep = "-" ;

public String getDate(int format,String separator) {
this.format = format;
Date xdate = new Date();
java.util.Calendar rightNow = java.util.Calendar.getInstance();
rightNow.setTime(xdate);
String year = String.valueOf(rightNow.get(java.util.Calendar.YEAR));
String month = String.valueOf(rightNow.get(java.util.Calendar.MONTH) + 1);
String day = String.valueOf(rightNow.get(java.util.Calendar.DATE));

if (day.length() < 2) {
day = "0" + day;
}
if (month.length() < 2) {
month = "0" + month;
}
if (separator == null) {
separator = sep ;
}

String ndate = year + "-" + month + "-" + day;
ndate = year + month + day;
switch ( format) {
case 0 :
ndate = day+separator+month+separator+year.substring(year.length()-2) ;
break;
case 1 :
ndate = day+separator+month+separator+year ;
break;
case 2 :
ndate = month+separator+day+separator+year ;
break;
case 3 :
ndate = day+month+year ;
break;
case 4 :ndate = month+day+year ;
break;
}

return ndate;
}



public boolean validateDate(String stringdate) {
boolean valid = false;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, Integer.parseInt(stringdate.substring(8, 10) ) );
cal.set(Calendar.MONTH, Integer.parseInt(stringdate.substring(5, 7))-1 );
cal.set(Calendar.YEAR, Integer.parseInt(stringdate.substring(0, 4)) );
try {
cal.getTime();
valid = true;
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());

}

return valid;
}


public Date setDate(String dte) {

String dyStr = dte.substring(6, 8);
String mtStr = dte.substring(4, 6);
String yrStr = dte.substring(0, 4);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, Integer.parseInt(dyStr));
cal.set(Calendar.MONTH, Integer.parseInt(mtStr));
cal.set(Calendar.YEAR,Integer.parseInt(yrStr));

try {
cal.getTime();
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
}
return new Date();
}

public boolean isDate(Date date) {
Date olddate = setDate("12610101");
if (!date.equals(olddate)) {
return false;
}
return true;
}









}

1 comment:

  1. New user
    *
    Posts: 16



    View Profile Personal Message (Online)
    Design Issue........can any one help????
    « on: February 27, 2010, 09:01:49 am » Reply with quote Modify message Remove message
    subse pehle toh holi ki bhaut bhaut shub kaamnayee!!!


    happy holi in advance..........


    sub mana rahe hain holi aur hum yeha office mei sad rahe hain......


    kher now comming to the point...










    ok so ppl the problem is regarding a design issue in my project.....

    as we all know if we append table in a form it becomes scrollable but if the table is drawn on canvas it cannot be scrolled... wat the problem is here is tat i have a datatable which has to be displayed and the table has 19 coloums and 15 rows!!!

    the table has to be scrollable at the same time also the data which has to be displayed on the table will not be static it will be dynamic. i tried it out on simple table it worked but the problem comes when the data in the table changes with high speed as every time when the model of table is changed event "firetablemodelchanged" has to be fired this leads to the distortion in display......


    so any one out there who can help me with this problem.....


    i was thinking of coding a new custom component for this issue will tat be a wise thing to do or any sugestion regarding this.....


    and one more thing if any one out there who can help me develop this custom component will be a great favour......


    regards

    Happy Holi again.....

    Enjoy...
    Report to moderator 122.163.115.178
    bonjovi4u
    New user
    *
    Posts: 16



    View Profile Personal Message (Online)
    Re: Design Issue........can any one help????
    « Reply #1 on: Today at 07:54:51 AM » Reply with quote Modify message Remove message
    so finally i had the word with my T.L and now the need of project is to draw a table on canvas which means tat the the canvas must be scrollable!!!!


    has any one done this before???

    if anyone there who has done this before can u pls send some sample code for the following need!!

    m really bad Designer!!

    Grin Grin Grin Grin Grin
    Report to moderator 122.177.81.125
    aclelland
    J2me god
    *****
    Posts: 2030


    aclelland@gmail.com
    View Profile Email Personal Message (Offline)
    Re: Design Issue........can any one help????
    « Reply #2 on: Today at 11:03:22 AM » Reply with quote
    what sort of data is being displayed on the table?
    Report to moderator Logged
    Who is John Galt?
    bonjovi4u
    New user
    *
    Posts: 16



    View Profile Personal Message (Online)
    Re: Design Issue........can any one help????
    « Reply #3 on: Today at 11:56:13 AM » Reply with quote Modify message Remove message
    the which has to be displayed on the table is stored in String data[]

    and the data which is stored is being updated on run time or u can call it real time data

    ReplyDelete