How to calculate time in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ramkrish
    New Member
    • Jul 2006
    • 3

    #1

    How to calculate time in java

    i have already used Simple Date Format method.i got the time from the system.that i am stored in sql.in sql i used datetime datatype.it gives date and time.but i need only time.and how to subtract the time.
  • lottalava
    New Member
    • Jul 2006
    • 13

    #2
    The method getTime( ) gives to you how many milisecs are since 1900 ( i think ), use it to make all operations you need.

    Comment

    • Ramkrish
      New Member
      • Jul 2006
      • 3

      #3
      hi ,
      Thank u for ur reply.Do u know how to increase the column width in JTable.

      Comment

      • mahammadseeraz
        New Member
        • Jul 2007
        • 6

        #4
        1. declare a long type variable --> long lng;
        2. assign it to time --> lng=System.curr entTimeMillis() ;
        --> System.out.prin tln(lng);


        import java.util.*;

        class time
        {
        public static void main (String[] arg){
        long lng;
        lng=System.curr entTimeMillis() ;
        System.out.prin tln(lng);
        }
        }

        it'll print system time since 1980..........? ????

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by mahammadseeraz
          it'll print system time since 1980..........? ????
          That's why it's so comfortable to have all the API documents available locally:

          Originally posted by System API docs
          Returns the current time in milliseconds. Note that while the unit of time of the
          return value is a millisecond, the granularity of the value depends on the
          underlying operating system and may be larger. For example, many operating
          systems measure time in units of tens of milliseconds.
          See the description of the class Date for a discussion of slight discrepancies
          that may arise between "computer time" and coordinated universal time (UTC).

          Returns:
          the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
          kind regards,

          Jos

          Comment

          • blazedaces
            Contributor
            • May 2007
            • 284

            #6
            Originally posted by Ramkrish
            hi ,
            Thank u for ur reply.Do u know how to increase the column width in JTable.
            Ok, what you're going to want to do is use JTable's getColumnModel( ) method and then afterwards use the TableColumnMode l's getColumn(index ) method. Then just set the preferred/max/min widths. Check out the following documentation on both of them:

            http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTable.html

            http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/table/TableColumnMode l.html

            http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/table/TableColumn.htm l

            I've done this before so though I know it's not the easiest concept, try it for yourself and tell me if you get stuck on a problem.

            Good luck,
            -blazed

            Comment

            Working...