|
| |||||||||
| Tags: database, date, date format, format, java, programming language, query |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Query with Date in java
Hello, I am trying a program in java which is related to Date format. But i think i have a problem with date in java. Here is my code, just go through it Code: Calendar cal = Calendar.getInstance(Local.ENGLISH);
cal.setTimeInMillis(1000);
String date = String.function valueOf() {
[native code]
}(cal.get(Calendar.HOUR))+":"+
String.function valueOf() {
[native code]
}(cal.get(Calendar.MINUTE))+":"+
String.function valueOf() {
[native code]
}(cal.get(Calendar.SECOND)); |
|
#2
| |||
| |||
| Re: Query with Date in java
Hello, This is normal, because getInstance (Local) only modifies the localization (language + format) but not the time zone (which is the default). If you want to use the GMT time zone as I think you should specify it explicitly. Code: Calendar cal = Calendar.getInstance(TimeZone.getTimezone("GMT")); |
|
#3
| |||
| |||
| Re: Query with Date in java
Hello, When using the function getTime () of the Calendar class to get a Date object, it returns automatically to local time. Code: Calendar cal = Calendar.getInstance(TimeZone.getTimezone("GMT"));
cal.set(Calendar.HOUR_OF_DAY, 23);
System.out.System.out.println(cal.get(Calendar.HOUR_OF_DAY) );
/ / 25 well done
System.out.System.out.println(cal.getTime().getHours());
/ / gives 1 ... |
|
#4
| |||
| |||
| Re: Query with Date in java
Hello, I think you are getting it wrong. Already method getHours () is deprecated and should not be used, then in its documentation it is stated that the reference time in the timezone of the machine and if you have the same timezone as me there are 2 hours apart with the GMT time zone. If you want more information on this then you can visit the official site of the sun for the api on java, that will definitely help you. |
|
#5
| |||
| |||
| Re: Query with Date in java
Hello, Just have a look at the following code, this is the basic code showing how to use the format of date in java. Code: DateFormat dtfr = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss");
java.util.Date dt = new java.util.Date ();
String dtStr = dtfr.format (dt);
try{
Date dt2 = dtfr.parse (dtStr);
}catch(ParseException pe){
pe.printStackTrace();} |
|
#6
| |||
| |||
| Re: Query with Date in java
Hello, This is a advanced code, please go through it and understand as much as you can. Code: public boolean isAfterPayDay(DateTime dttm) {
if (dttm.getMonthOfYear() == 2) { // February is month 2!!
return dttm.getDayOfMonth() > 26;
}
return dttm.getDayOfMonth() > 28;
}
public Days daysToNewYear(LocalDate fromDate) {
LocalDate nwy = fromDate.plusYears(1).withDayOfYear(1);
return Days.daysBetween(fromDate, nwy);
}
public boolean isRentalOverdue(DateTime dttmRented) {
Period rntprd = new Period().withDays(2).withHours(12);
return dttmRented.plus(rntprd).isBeforeNow();
}
public String getBirthMonthText(LocalDate dateOfBirth) {
return dateOfBirth.monthOfYear().getAsText(Locale.ENGLISH);
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Query with Date in java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sql query for Date function. | horuy | Software Development | 3 | 17-11-2010 12:22 AM |
| Query in java classes | Aaliya Seth | Software Development | 5 | 26-02-2010 01:34 AM |
| Query regarding use of ActionListener in java | beelow | Software Development | 3 | 16-11-2009 10:56 AM |
| [JAVA] query results in a combobox and jtextfield | Aamin | Software Development | 5 | 31-03-2009 03:20 PM |
| Query Disabled Date | Kurt Levitan | Window 2000 Help | 5 | 09-11-2007 08:20 PM |