This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

java date related problems  RSS feed

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My application demands generating a current date and depending on the condition set an alarm for 24 , 48 or 72 hours.
What I need is to generate a java.sql.Date date which I can pass to a method which does the needed functionality
Here goes my code
long now = System.currentTimeMillis(); //The current time
long 24HourFromNow = now + (24 * 60 * 60 * 1000);
long 48HourFromNow = now + (48 * 60 * 60 * 1000);
long 72HourFromNow = now + (72 * 60 * 60 * 1000);

java.sql.Date dtAlarm = null;

if ( sPenaltyColumn.equals("24") ) {
b24Hour = true;
dtAlarm = new date(24HourFromNow);
penalty = true;
}
else if ( sPenaltyColumn.equals("48") ) {
b48Hour = true;
dtAlarm = new date(48HourFromNow);
penalty = true;
}
else if ( sPenaltyColumn.equals("72") ) {
b72Hour = true;
dtAlarm = new date(72HourFromNow);
penalty = true;
}
markPlayerPenalty(b24Hour, b48Hour, b72Hour, sPlayerID, dtAlarm, con);
When I run this code, I get the following exceptions
Fri Apr 06 22:22:29 GMT+00:00 2001:<E> <ServletContext-Servlets> weblogic.servlet.JSPServlet: Compilation of /opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java failed: /opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java:296: Invalid expression statement.
long 24HourFromNow = now + (24 * 60 * 60 * 1000); //[ EnforcePlayer.jsp; Line: 242]
^
/opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java:296: ';' expected.
long 24HourFromNow = now + (24 * 60 * 60 * 1000); //[ EnforcePlayer.jsp; Line: 242]
^
/opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java:296: Invalid character in number.
long 24HourFromNow = now + (24 * 60 * 60 * 1000); //[ EnforcePlayer.jsp; Line: 242]
^
/opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java:297: Invalid character in number.
long 48HourFromNow = now + (48 * 60 * 60 * 1000); //[ EnforcePlayer.jsp; Line: 243]
^
/opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java:298: Invalid character in number.
long 72HourFromNow = now + (72 * 60 * 60 * 1000); //[ EnforcePlayer.jsp; Line: 244]
^
/opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java:304: Invalid character in number.
dtAlarm = new date(24HourFromNow); //[ EnforcePlayer.jsp; Line: 250]
^
/opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java:309: Invalid character in number.
dtAlarm = new date(48HourFromNow); //[ EnforcePlayer.jsp; Line: 255]
^
/opt/devpkg/weblogic_instances/wl9000/classfiles/jsp/_EnforcePlayer.java:314: Invalid character in number.
dtAlarm = new date(72HourFromNow); //[ EnforcePlayer.jsp; Line: 260]
^
8 errors

As an alternative, I developed another code to do the same task

java.util.Date today = new java.util.Date();
System.oout.println("today : "+today);
Calendar cal = Calendar.getInstance();
System.oout.println("cal : "+cal);
cal.setTime(today);
System.oout.println("cal : "+cal);
cal.add(Calendar.DATE,1) // Add 1 day or 24 hours
java.util.Date expiration = cal.getTime();
System.oout.println("expiration : "+expiration);
java.sql.Date dtAlarm = ( java.sql.Date ) expiration;
System.oout.println("dtAlarm : "+dtAlarm);
but when I run this code , This time I am getting a null pointer exception
today : Fri Apr 06 19:45:30 GMT+00:00 2001
cal : java.util.GregorianCalendar[time=986586330917,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=java.util.SimpleTimeZone[id=Custom,offset=0,dstSavings=3600000,useDaylight=fa lse,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0],firstDayOfWeek=1,minimalDaysInFirstWeek=1,E RA=1,YEAR=2001,MONTH=3,WEEK_OF_YEAR=14,WEEK_OF_MONTH=1,DAY_OF_MONTH=6,DAY_OF_YEAR=96,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=7,HOUR_OF_DAY=19,MINUTE=45,SECOND=30,MILLISEC OND=917,ZONE_OFFSET=0,DST_OFFSET=0]
cal : java.util.GregorianCalendar[time=986586330915,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=java.util.SimpleTimeZone[id=Custom,offset=0,dstSavings=3600000,useDaylight=fa lse,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0],firstDayOfWeek=1,minimalDaysInFirstWeek=1,E RA=1,YEAR=2001,MONTH=3,WEEK_OF_YEAR=14,WEEK_OF_MONTH=1,DAY_OF_MONTH=6,DAY_OF_YEAR=96,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=7,HOUR_OF_DAY=19,MINUTE=45,SECOND=30,MILLISEC OND=915,ZONE_OFFSET=0,DST_OFFSET=0]
Exception caught : null
java.lang.NullPointerException
at jsp._EnforcePlayer._jspService(_EnforcePlayer.java:302)
at weblogic.servlet.jsp.JspBase.service(Compiled Code)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Compiled Code)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Compiled Code)
at weblogic.servlet.JSPServlet.service(Compiled Code)
at javax.servlet.http.HttpServlet.service(Compiled Code)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Compiled Code)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Compiled Code)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Compiled Code)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(Compiled Code)
at weblogic.socket.MuxableSocketHTTP.execute(Compiled Code)
at weblogic.t3.srvr.ExecuteThread.run(Compiled Code)
I am always getting stuck with date related problems in Java , I hope handling date in java would have been made much easier .

Can someone suggest a suitable source on the net for java date related stuff ?
 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Guys there was this violation of naming convention for identifiers so I was getting this errors. The identifier name should not start with a number
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!