The Artima Developer Community
Sponsored Link

Java Answers Forum
Date of system

8 replies on 1 page. Most recent reply: Aug 11, 2004 8:20 PM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Nick

Posts: 9
Nickname: nicolashad
Registered: Jul, 2004

Date of system Posted: Jul 1, 2004 8:27 AM
Reply to this message Reply
Advertisement
hi!
I would know how it is the code for take the date of the system (pc). I'll do compare this date with another date, just inside the data base.
Thanks!


p.s. sorry for my bad english, I'm italian


Harry Paek

Posts: 3
Nickname: harrypaek
Registered: Jul, 2004

Re: Date of system Posted: Jul 1, 2004 6:18 PM
Reply to this message Reply
Hi!

You Can Get System Time using
GregorianCalendar class

GregorianCalendar myCalendar = new GregorianCalendar();


Good Luck!
Bye.

Nick

Posts: 9
Nickname: nicolashad
Registered: Jul, 2004

Re: Date of system Posted: Jul 2, 2004 12:54 AM
Reply to this message Reply
Thanks!!

Nick

Posts: 9
Nickname: nicolashad
Registered: Jul, 2004

Re: Date of system Posted: Jul 2, 2004 9:07 AM
Reply to this message Reply
Hi,thanks, but it don't fuction.I would take the "now" and put it in the "Date today" where "today = new date()".Someone know if exist a line of code to do it?
Thanks

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Date of system Posted: Jul 2, 2004 6:46 PM
Reply to this message Reply
I'm not sure what you mean. When you create a Date() object, it's date/time is now:

public class Now
{
   public static void main( String [] args )
   {
      java.util.Date now = new java.util.Date();
      System.out.println(now);
   }
}


Is that what you're looking for? Or...?

Nick

Posts: 9
Nickname: nicolashad
Registered: Jul, 2004

Re: Date of system Posted: Jul 5, 2004 6:02 AM
Reply to this message Reply
thanks!
i'll would take the date of system, ithink it's called "now" for do this:

if (data.before(today)) {
java.sql.PreparedStatement ps2 = conn.prepareStatement("update percorsi set stato = ? where id_percorso = ?");
ps2.setString(1, "N");
ps2.setString(2, id);
int result2 = ps2.executeUpdate();
ps2.close();
}}
rs.close();
ps.close();
conn.close();%>

the code that i write down is this:


<jsp:include page="include/defineConnection.jsp"/>
<% java.sql.Connection conn = java.sql.DriverManager.getConnection((String) request.getAttribute("DBConnection"), "", "");
java.sql.PreparedStatement ps = conn.prepareStatement("select * from percorsi");
java.sql.ResultSet rs = ps.executeQuery();
while (rs.next()) {
String id = (String) rs.getString(1);
java.util.Date data = (java.util.Date) rs.getDate(5);
String[] ids = java.util.TimeZone.getAvailableIDs(+1 * 60 * 60 * 1000);
java.util.SimpleTimeZone pdt = new java.util.SimpleTimeZone(+1 * 60 * 60 * 1000, ids[0]);
java.util.Calendar cal = new java.util.GregorianCalendar(pdt);
//java.util.Date today = cal.get(java.util.Calendar.DATE);
int d = cal.get(java.util.Calendar.DAY_OF_MONTH);
int m = cal.get(java.util.Calendar.MONTH);
int y = cal.get(java.util.Calendar.YEAR);
String oggi = d + "/" + m + "/" + "y";
java.util.Date today = java.sql.Date.valueOf(oggi);
/*if (E.before(today) == true) {*/if (data.before(today)) {
java.sql.PreparedStatement ps2 = conn.prepareStatement("update percorsi set stato = ? where id_percorso = ?");
ps2.setString(1, "N");
ps2.setString(2, id);
int result2 = ps2.executeUpdate();
ps2.close();
}}
rs.close();
ps.close();
conn.close();%>

Harry Paek

Posts: 3
Nickname: harrypaek
Registered: Jul, 2004

Re: Date of system Posted: Jul 5, 2004 6:33 PM
Reply to this message Reply
Hi!

I'm not sure what you mean
But if I were you, I'll try it like bellow
============================================
I supposed

You just want update DB data record
where date_column value is earlier than today
and no other conditions


I think with JUST one short SQL statement can solve your problem.
So I tried to build SQL

Because I don't know about JSP things
I just show You this SQL

update percorsi
set stato = 'N'
where Date_Column < TO_DATE(TO_CHAR(SYSDATE, 'DD/MM/YYYY'), 'DD/MM/YYYY')


I hope this helps you
Good Luck!

Radhika Padmini

Posts: 1
Nickname: radhika
Registered: Aug, 2004

Re: Date of system Posted: Aug 10, 2004 11:53 PM
Reply to this message Reply
hi, I want to get the system date in the format dd-mm-yy

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Date of system Posted: Aug 11, 2004 8:20 PM
Reply to this message Reply
package test;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class Test {
  public static void main(String[] args) {
    
    SimpleDateFormat simpleFormatter = new SimpleDateFormat("dd-MM-yy");    
    
    // Get current date
    Date today = new Date();
    
    // Format the current date
    String formattedDate = simpleFormatter.format (today);
  
    // Print the date
    System.out.println("Today is (dd-MM-yy):" + formattedDate);  
  }
}
 

Flat View: This topic has 8 replies on 1 page
Topic: J2EE OPENING Previous Topic   Next Topic Topic: Java/C++ point to same datastructure

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use