KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > sql > Timestamp

java.sql
Class Timestamp

java.lang.Object
  extended by java.util.Date
      extended by java.sql.Timestamp
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Date>
See Also:
Top Examples, Source Code

public boolean after(Timestamp ts)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[863]Change date to the last day of the prev month from a Timestamp object
By Anonymous on 2004/08/19 13:21:04  Rate
//change date to the last day of the prev month from a Timestamp object 
 Timestamp ts = new Timestamp ( System.currentTimeMillis (  )  ) ; 
 System.out.println ( ts ) ; 
  
  
 Calendar cal = GregorianCalendar.getInstance (  ) ; 
 cal.setTimeInMillis ( ts.getTime (  )  ) ; 
  
  
 cal.add ( Calendar.MONTH, -1 ) ; 
  
  
 cal.set ( Calendar.DAY_OF_MONTH, cal.getActualMaximum ( Calendar.DAY_OF_MONTH )  ) ; 
  
  
 ts.setTime ( cal.getTimeInMillis (  )  ) ; 
 System.out.println ( ts ) ; 
  
  
 //after


public boolean before(Timestamp ts)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int compareTo(Timestamp ts)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1874]encrypt
By prerak85 { at } gmail { dot } com on 2007/04/23 00:54:39  Rate
 
 import java.math.BigInteger; 
  
  
 public class encrypt 
  {  
   public static void main ( String [  ]  args )  
    {  
       //compute pow ( x, n )  % p 
     BigInteger x = BigInteger.valueOf ( 7 ) ; 
     BigInteger n = BigInteger.valueOf ( 83149027 ) ; 
     BigInteger p = BigInteger.valueOf ( 8325467 ) ; 
     BigInteger start = BigInteger.ZERO; 
     int i = 0, a = 0; 
     int [  ]  array; 
     BigInteger ans = BigInteger.ZERO; 
     start = x.mod ( p ) ; 
     array = new int [ 200000 ] ; 
     int result = 0; 
      
     int check = n.intValue (  ) ; 
      
     while  ( check != 0 )  
      {  
  
  
       if  ( check % 2 == 0  ) // if n is even 
        {  
         array [ i ]  = check; 
         i++; 
         check = check / 2;   
        }  
       else if  ( check % 2 == 1 ) // if n is odd 
        {  
         array [ i ]  = check; 
         i++; 
         check = check - 1; 
          
         array [ i ]  = check; 
         i++; 
         check = check / 2; 
  
  
        }  
       else 
         System.out.println ( "Mistake somewhere" ) ; 
  
  
        
      }  
      
     for ( int j = 0; j  <  array.length; j++  )   
      {  
       if ( array [ j ]  !=0 )  
        {  
           a++;     
        }  
           else 
             break; 
         }  
         
        int [  ]  newarray = new int [ a ] ; 
        for  ( int r = 0; r  <  a; r++ )  
         {  
          newarray [ r ]  = array [ r ] ;   
         }  
         
        ans = start; 
        for ( int m = newarray.length - 2; m  > = 0; m-- )  
         {  
           
          if ( newarray [ m ]  % 2 == 0 )  
           {  
  
  
              ans = ans.multiply ( ans ) ; 
              ans = ans.mod ( p ) ; 
           }        
        else if  ( newarray [ m ]  % 2 == 1 )  
         {  
          ans = start.multiply ( ans ) ; 
          ans = ans.mod ( p ) ; 
         }  
        else  
          System.out.println ( "Something is wrong" ) ; 
   
         }  
      System.out.println ( " ( "+ x + " ^ " + n + " )  % " + p + " = " + ans ) ; 
       
    }  
  } 


public int compareTo(Date o)
See Also:
ClassCastException, Comparable, compareTo
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean equals(Object ts)
See Also:
Date.getTime()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean equals(Timestamp ts)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getNanos()
See Also:
setNanos(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public long getTime()
See Also:
setTime(long), Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[846]Date Time Format with Timezone
By Anonymous on 2004/08/02 21:13:18  Rate
public static void main ( String [  ]  args )   {  
     System.out.println ( "DateTime is "+getDate (  ) +"T"+getTime (  )  ) ; 
     System.out.println ( "DateTime is "+getDateTime (  ( getDate (  ) +getTime (  )  ) .toString (  )  )  ) ; 
     //System.out.println ( "Timezone is+ "+ TimeZone.getDefault (  )  ) ; 
    }  
    
   private  final static String getDate (  )   {  
         DateFormat df = new SimpleDateFormat ( "yyyy-MM-dd" ) ; 
         df.setTimeZone ( TimeZone.getTimeZone ( "PST" )  ) ; 
         return toUpperCase ( df.format ( new Date (  )  )  ) ; 
      }  
      
   private  final static String getTime (  )   {  
         DateFormat df = new SimpleDateFormat ( "hh:mm:ss:z" ) ; 
         //df.setTimeZone ( TimeZone.getTimeZone ( "PST" )  ) ; 
         df.setTimeZone ( TimeZone.getTimeZone ( "America/Los_Angeles" )  ) ;         
  
  
         return toUpperCase ( df.format ( new Date (  )  )  ) ; 
      }  
    
     private  final static String getDateTime ( String s )   {  
         DateFormat df = new SimpleDateFormat ( "s" ) ; 
         df.setTimeZone ( TimeZone.getTimeZone ( "PST" )  ) ; 
         return toUpperCase ( df.format ( new Date (  )  )  ) ; 
      }  
      
 //    private getZone (  )  {  
 //      return getTimeZone (  ) ; 
 // 
 //     }  
  
  
   protected static String toUpperCase ( String val )   {  
      if  ( val == null )  
        return ""; 
      return val.toUpperCase (  ) ; 
    } 


[1533]The subtle difference of getTime() between 1.3.1 and the later ones
By Anonymous on 2005/09/13 06:44:18  Rate
Note the subtle difference between 1.3.1 and the later ones: The following lines appear in the 1.3.1 Javadoc, but were removed in subsequent version. 
  
  
     The getTime method will return only integral seconds. If a time value that includes the fractional seconds is desired, you must convert nanos to milliseconds  ( nanos/1000000 )  and add this to the getTime value.  
  
  
 If your code needs to run on JDK 1.3 and later, you??ll have to do this: 
     
 java.sql.Timestamp timestamp = resultSet.getTimestamp ( 1 ) ; 
 long millis =  ( timestamp.getTime (  )  / 1000 )  * 1000 + timestamp.getNanos (  )  / 1000000; 
 java.util.Date d = new java.util.Date ( millis ) ;


public void setNanos(int n)
See Also:
getNanos(), IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setTime(long time)
See Also:
for more information, Timestamp(long time), getTime(), Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public Timestamp(int year,
                            int month,
                            int date,
                            int hour,
                            int minute,
                            int second,
                            int nano)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Timestamp(long time)
See Also:
for more information
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[312]_
By Anonymous on 2003/11/29 10:12:15  Rate
Timestamp ts = new java.sql.Timestamp ( System.currentTimeMillis (  )  ) ;

public String toString()
See Also:
Date.toGMTString(), Date.toLocaleString()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[585]Throw away date
By Anonymous on 2003/12/23 09:44:58  Rate
String timestr = new String ( Rx2Time.toString (  )  ) ;  
 /* throw away date */ 
 outputBuffer.append ( timestr.substring ( timestr.indexOf ( ' ',2 )  )  ) ;


[819]_
By Anonymous on 2004/06/24 03:47:40  Rate
String start= (  ( java.sql.Timestamp ) pageContext.getAttribute ( "startAendern",PageContext.SESSION_SCOPE )  ) .toString (  ) ;

public static Timestamp valueOf(String s)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags