Getting a date as a unix timestamp

Hello everyone,
is the long that is returned by the getTime() method in the date class supposed to be the same as a unix timestamp?
Below I have a time from yesterday, but when i compare this with System.currentTimeMillis(), the currentTime has a smaller timestamp
code]SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-kk:mm:ss");
          long expiryDate=0;
          try{
               Date d = sdf.parse("11-11-2006-19:07:50");
               expiryDate = d.getTime(); results in 1163358470000
          catch(ParseException pe){
               pe.printStackTrace();
yesterdays time is 1163358470000
current time is 1163355193562 // smaller number
Whats going on?

sorry, here it is again
is the long that is returned by the getTime() method in the date class supposed to be the same as a unix timestamp?
Below I have a time from yesterday, but when i compare this with System.currentTimeMillis(), the currentTime has a smaller timestamp
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-kk:mm:ss");
long expiryDate=0;
try{
Date d = sdf.parse("11-11-2006-19:07:50");
expiryDate = d.getTime(); results in 1163358470000
catch(ParseException pe){
pe.printStackTrace();
}yesterdays time is 1163358470000
current time is 1163355193562 // smaller number
Whats going on?

Similar Messages

  • Select entries between two dates by converting Unix timestamp in Oracle Dat

    Hi,
    I need to select the entries between two dates from an Oracle db. The Oracle db has a column with Unix timestamps. I use the following querry, but it doesnt seem to be working as desired.
    select count(*) from reporter_status where to_char(FIRSTOCCURRENCE, 'mm-dd-yy') between ('08-07-06') and ('08-08-06');
    FIRSTOCCURRENCE has the Unix timestamps.
    Could anyone help me out with this. Thank you for your help.

    Assuming that it is actually a UNIX timestamp, then it is the number of seconds since Jan 1, 1970, so you need something like:
    SELECT COUNT(*)
    FROM reporter_status
    WHERE TO_DATE('01-Jan-1970', 'dd-mon-yyyy') + (firstoccurrence/24/60/60)
                    BETWEEN TO_DATE('08-07-2006', 'mm-dd-yyyy') AND
                            TO_DATE('08-08-2006, 'mm-dd-yyyy');Did Y2K not teach us anything? Use 4 digit years.
    John

  • Update date/time in UNIX timestamp format

    The datetime in my Oracle DB is being stored in UNIX Date Time format.
    Is there a way I can set the date/time using an UPDATE statement in such a case.
    for eg:
    select id, creation_date, expiration_date from skel;
    id creation_date expiration_date
    400019 1213726470     
    400020 1213733052     
    400005 1210867973     
    400018 1213723608     
    I am looking to set the expiration date as creation_date + 1 year.
    Could you please advise?

    I am looking to update the value in the field. The values will still be in UNIX date/time format.Yes, but still: instead of continuing converting to Oracle dates and Unix dates, why not just store dates the way the datebase can deal with it the best?
    You're probably storing your UNIX date/time formatted dates in the database as NUMBERS.
    That is a great loss of lots of built-in date functionality Oracle Database provides.
    If you insist on staying on that road, then explore my previous links, you will find your answer:
    Convert epoch number to date, do arithmatic and convert the result back to epoch number.
    That is overkill.
    It won't work/scale/perform/whatever in the end. It is a bad approach.
    So, please reconsider this:
    Why are you storing dates as numbers?
    Convert those numbers to dates once, and be done with it for ever after and benefit from all the builtin date-functionality Oracle database comes with, or convince us that you really have a valid reason to store dates in UNIX date/time format into an Oracle Database.
    and my last date was...uuhhmm... never mind ;)

  • Getting Date from a Unix format Timestamp

    Hi there,
    I am having trouble with a WebService i am using to get some information. When i get it, the date of the different data i receive is a timestamp like 1198113192912. This number contains the milliseconds passed since the 1st of January, 1970.
    The thing is that i have been looking for a MF that allows me to get the date in a readable format, but it seems that the timestamps used in SAP are slightly different, and thus, useless for me.
    I would appreciate it a lot if anyone could help me out with this issue, since i do really need to have this sorted out quite soon.
    Thanks in advance
    Diego
    Edited by: di die on Jan 25, 2008 9:41 AM

    Hi there,
    I am having trouble with a WebService i am using to get some information. When i get it, the date of the different data i receive is a timestamp like 1198113192912. This number contains the milliseconds passed since the 1st of January, 1970.
    The thing is that i have been looking for a MF that allows me to get the date in a readable format, but it seems that the timestamps used in SAP are slightly different, and thus, useless for me.
    I would appreciate it a lot if anyone could help me out with this issue, since i do really need to have this sorted out quite soon.
    Thanks in advance
    Diego
    Edited by: di die on Jan 25, 2008 9:41 AM

  • How can i convert the firefox-history-timestamp in places.sqlite into a normal date format? The firefox-timestamp is not equivalent to the unix-timestamp, that's why I ask. I could not find a conversion function. Does anyone know something about this?

    As I opened the places.sqlite with an sqlite-editor I found out that firefox saves the last_visit_date via a timestamp which is 16 digits long. I realized that the first 10 digits are similar to the corresponding unix-timestamp but not equal. So.. how can i convert the firefox-timestamp into a normal date? Or into the corresponding unix-timestamp?

    Write a bash script or 'C' program to change the date format and then use the sql update function to receive the stdio output 'where date_field='embeded date value'.

  • Unix Timestamp to date

    hi,
    I am using SQL developer to query an oracle 8 Database and
    I need to convert a unix timestamp to a specific date time format - YYYYMMDD HH24:MI:SS
    I am currently using
    ,to_date('19700101 00:00:01','YYYYMMDD HH24:MI:SS')+sh.order_date/86400
    but this just returns the date in the format DD-MMM-YY

    Hi,
    Welcome to the forum!
    What is a unix timestamp?
    If it's the number of seconds since mdinight on January 1, 1970, then you can convert that to a DATE like this:
    DATE '1970-01-01' + ( unix_timestamp
                       / (24 * 60 * 60)
                  )To display any DATE in a specific format, use TO_CHAR:
    TO_CHAR ( DATE '1970-01-01' + ( unix_timestamp
                                  / (24 * 60 * 60)
         , 'YYYYMMDD HH24:MI:SS'
         )

  • Getting current date and timestamp for timezone

    I am getting the current date and timestamp using
    Date d = new Date();
    On the platform I'm using it is returning it in GMT time.
    I want to convert this into Eastern Time Zone for United Status.

    java.util.Date objects contain a count of milliseconds since the "epoch", which happens to be midnight, Jan 1 1970 GMT. However, they aren't intrinsically "in" any timezone.
    If you simply call Date.toString(), you'll get the date formatted for the current locale, including timezone.
    If you want a different format, you can use the DateFormat or SimpleDateFormat classes (recommended), or use Calendar to pull the various date components out. You have to physically set the timezone for each of these.
    To get a list of timezones supported by your machine, you can run this program:
    import java.util.Arrays;
    import java.util.TimeZone;
    public class TZDump
        public static void main(String[] argv)
        throws Exception
            String[] zones = TimeZone.getAvailableIDs();
            Arrays.sort(zones);
            for (int ii = 0 ; ii < zones.length ; ii++)
                System.out.println(zones[ii]);
    }And, here's a program that lets you compare the same date in different timezones:
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.TimeZone;
    public class TZDemo
        public static void main(String[] argv)
        throws Exception
            SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
            Date now = new Date();
            System.out.println("Default TZ = " + fmt.format(now));
            String[] zones = new String[] { "EST", "EST5EDT", "PST"};
            for (int ii = 0 ; ii < zones.length ; ii++)
                fmt.setTimeZone(TimeZone.getTimeZone(zones[ii]));
                System.out.println("EST        = " + fmt.format(now));
    }

  • How to get Unix timestamp?

    Hi All,
    Didn't find any solution with a search so asking if somebody's already implemented a method to get a Unix timestamp in BPEL? It's a number of seconds since Jan-1-1970. I'm quite new to BPEL so any help is appreciated!
    Thank you in advance,
    Philipp

    Hi Philipp,
         One approach can be to use Java embedding in BPEL to get Unix timestamp.
    Check this out Java Embedding Activity in BPEL | Oracle SOA Training | BPEL, OSB, BAM, OWSM, B2B |ORACLE FUSION MIDDLEWARE SCHOOL
    Ref: Incorporating Java and Java EE Code in a BPEL Process
    -- Sid

  • Unix timestamp to Oracle timestamp conversion

    Hi all,
    I am trying to convert the UNIX timestamp to ORACLE timestamp .
    I have done like this upto now.
    CREATE OR REPLCACE FUNCTION unixts_to_oraclets(unixtimestamp IN INTEGER)
    RETURN DATE IS
    result DATE;
    BEGIN
    result := TO_DATE('1970-01-01', 'YYYY-MM-DD') + numtodsinterval(unixtimestamp, 'SECOND');
    return(result);
    end unixts_to_oraclets;
    now i have run this query
    SQL> select unixts_to_oraclets(1139291114) as TS from dual;
    TS
    07-FEB-06
    now i need the ouput to like this 07-FEB-06 01:10:12
    for that i have done like this:
    DECLARE
    v_date DATE;
    res_date DATE;
    BEGIN
    SELECT from_uts(1139291114)INTO v_date FROM dual;
    SELECT TO_TIMESTAMP(v_date,'DD-MON-RRHH24.MI.SS.FF') INTO res_date FROM dual;
    DBMS_OUTPUT.PUT_LINE(res_date);
    END;
    but the output is :
    SQL> /
    07-FEB-06
    PL/SQL procedure successfully completed.
    why is that it is not printing 07-FEB-06 01:10:12 ?
    how should i moodify the code to get the desired output.
    please help me i this regard
    Trinath Somanchi,
    Hyderabad.

    SQL> exec dbms_output.put_line(sysdate);
    07-FEB-06
    PL/SQL procedure successfully completed.
    SQL> exec dbms_output.put_line(to_char(sysdate, 'DD-MM-YYYY HH24:MI:SS'));
    07-02-2006 02:48:35
    PL/SQL procedure successfully completed.
    SQL> alter session set nls_date_format='DD-MM-YYYY HH24:MI:SS';
    Session altered.
    SQL> exec dbms_output.put_line(sysdate);
    07-02-2006 02:49:03
    PL/SQL procedure successfully completed.

  • Unix timestamp / epoch conversion in IQ

    Hello,
    I searched the community as well as some other historical locations, but couldn't find any discussions on this.
    In several of the projects I am working with, there is a source datetime field that always comes in as a unix timestamp (i.e. seconds since the epoch). The question I regularly get is, can we load this into IQ and have it converted during load from the integer into an IQ datetime column.
    I have my own suggestions for how to solve this already, but rather than influence the creative (or resolute) mind, I thought I'd put it out to the community to see how you have/would solve this issue?
    Thoughts??
    Thank you,
    -Joe Love
    SAP Mobile Services and Consumer Insights

    None that I am aware of during the LOAD TABLE event.  You can always load it and post process the data, but that's gets ugly and requires you to carry an extra column in your table.  My typical approach is to have the data converted before loading into IQ.  If the data is being touched by a streaming engine, ETL tool, or replication, you can do it all inline with those tools and a little coding.  For 3rd party tools, I would have them change their code to generate readable date/time stamps.  That or pre-process the data with something like sed or awk.
    Mark

  • Difference between timestamp oracle datatype as unix timestamp

    Hi
    We are having a column in our table as create_ts which is the time, the row is updated. We are in need to get this time in Pro*c as unix timestamp type to find out the oldest row from a set of rows.
    I found that the following query works when I convert to date and find out the difference.
    select TO_NUMBER((TO_DATE (TO_CHAR (CREATE_TS, 'YYYY-MON-DD HH24:MI:SS'),'YYYY-MON-DD HH24:MI:SS') - to_date('01.01.1970 00:00:00','dd.mm.yyyy HH24:mi:ss')) * 24 * 60 * 60 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600 ,9999999999) as timestamp from customer;
    However when I keep it as timestamp type I'm getting some error
    select TO_NUMBER((CREATE_TS - to_timestamp('01.01.1970 00:00:00','dd.mm.yyyy HH24:mi:ss'))* 24 * 60 * 60 *1000 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600000 ,9999999999999) as timeints from customer;
    ERROR
    ORA-30081: invalid data type for datetime/interval arithmetic
    30081. 00000 - "invalid data type for datetime/interval arithmetic"
    FYI: since if I convert to date type, we're losing the microseconds, we had to find the difference using the timestamp type.
    thanks

    When you take a difference between two timestamps, You dont get a number(like substracting dates). You get a string that has number of days,hours,minutes and seconds.
    You can break the string though,
    SQL> SELECT SUBSTR(today,1,30) today,
      2         SUBSTR(tomorrow,1,30) tomorrow,
      3         SUBSTR((tomorrow-today), INSTR((tomorrow-today),' ')+7,2) "SS",
      4         SUBSTR((tomorrow-today), INSTR((tomorrow-today),' ')+4,2) "MI",
      5         SUBSTR((tomorrow-today), INSTR((tomorrow-today),' ')+1,2) "HH",
      6         TRUNC(TO_NUMBER(SUBSTR((tomorrow-today),1, INSTR(tomorrow-today,' ')))) "Days"
      7    FROM (SELECT TO_TIMESTAMP(SYSDATE) today,TO_TIMESTAMP(SYSDATE+1) tomorrow FROM dual);
    TODAY                          TOMORROW                       SS MI HH       Days
    10-MAR-11 12.00.00 AM          11-MAR-11 12.00.00 AM          00 00 00          1
    SQL>
    SQL> G.

  • Unix timestamp with jsp

    hi all,
    i need to convert current time to unix timestamp. actaully i'm a PHP programmer but i plan to use jsp in the future. when i write web applications with PHP, i use mktime() function which converts any given time to unix timestamp value. so i store returned integer value to database as an integer field. this helps me when i need to compare dates with sql commands. and when i need to reconvert this integer to date value i use anoher php function date().
    so my question is, how can i do such a thing with java? people talk about a class java.sql.Timestamp, is it the timestamp that i look for?
    any helps (especially code samples) will be useful...

    ok i found out how to get the time in miliseconds. by getTime() method of Date class. but i still have problems. if u interested this topic is moved to java programming forum under title "date in miliseconds".

  • How do get particular date of total time

    this is our java code
        private static PreparedStatement preparedStatement;
        private static ResultSet rs;
        public static void main(String[] args) throws NamingException, SQLException
            int objectId;
            int clientId;
             DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // String gpstime = null;
             PreparedStatement preparedStatement = null;
             Connection conn=null;
             long mill;
             long diffSeconds=0;
             long diffMinutes=0;
             try
              Class.forName("com.mysql.jdbc.Driver");
            Connection conn1=DriverManager.getConnection("jdbc:mysql://108.108.8.4:3306/navl?","root", "ajmani@%");
            preparedStatement = conn1.prepareStatement("select gpstime from xydata a inner join fm4features f on a.ID=f.ID where a.objectId= '18'  AND a.clientId = '1' AND a.gpstime > '2010-05-11 00:00:00'  AND a.gpstime < '2010-05-13 23:59:59' AND f.DataId='1' AND f.value = '1'");
            rs = preparedStatement.executeQuery();
            int a = 0;
            int b=0;
             int b1=0;
             int b2=0;
             int x=0;
             float secs = 0;
            Set<String> dates = new HashSet<String>();
            ArrayList<Integer> l=new ArrayList<Integer>();
              Timestamp t1 = null;
              Timestamp t2 = null;
              int count  = 0;
              while ( rs.next() )
                    String gpstime = rs.getString("GpsTime");
                 if (dates.add(gpstime) )
                     //System.out.println(rs.getTimestamp(1));
                     t2 =   rs.getTimestamp(1);
                     count++;
                   if (t1 == null )
                       int nano = t2.getSeconds();
                         System.out.println(nano);
                       System.out.println(nano);
                       System.out.println(t2);
                       System.out.println(count);
                  else
                        mill= (t1.getTime() - t2.getTime())/-1;
                        //System.out.println(mill);
                        diffSeconds = mill / 1000;
                        diffMinutes = mill / (60 * 1000);
                        long diffHours = mill / (60 * 60 * 1000);
                        long diffDays = mill / (24 * 60 * 60 * 1000);
                        //System.out.println("\nThe Date Different");
                        //System.out.println("Time in milliseconds: " + mill+ " milliseconds.");
                        System.out.println("GPSTime " +gpstime+ " Time in seconds: " + diffSeconds+ " seconds.");
                        //System.out.println("Time in minutes: " + diffMinutes+ " minutes.");
                        //System.out.println("Time in hours: " + diffHours+ " hours.");
                        //System.out.println("Time in days: " + diffDays+ " days.");
                  t1 = t2;
                //System.out.println("Time in minutes: " + diffSeconds+ " seconds.");
                if(diffSeconds < 80)
                  b=(int) diffSeconds;
                  System.out.println(b);
                  l.add(b);
                 else if(diffSeconds > 80)
                    b2=(int)diffSeconds%60;
                    System.out.println(b2);
                    l.add(b2);
                 a++;
              for (int i=0; i<l.size();)
                  secs+=l.get(i);
                  i++;
                 System.out.println(secs);
                 int hours = (int) (secs / 3600),
                 remainder = (int) (secs % 3600),
                 minutes = remainder / 60,
                 seconds = remainder % 60;
                    String disHour = (hours < 10 ? "0" : "") + hours,
                    disMinu = (minutes < 10 ? "0" : "") + minutes ,
                    disSec = (seconds < 10 ? "0" : "") + seconds ;
                    if (count < 2)
                        int se = Integer.parseInt(disSec);
                        String min = (t2.getSeconds() < 10 ? "0" : "") + t2.getSeconds();
                        System.out.println("00" + ":" +  "00" + ":" + min + " hh:mm:ss");
                    System.out.println(disHour +":"+ disMinu+":"+disSec+ " hh:mm:ss");
             }catch(Throwable th)
               Logger.getLogger(testing1.class.getName()).log(Level.SEVERE, null, th);
             }finally
               if(preparedStatement!=null)
                   preparedStatement.close();
               if(conn!=null)
                   conn.close();
    }this is output
    GPSTime 2010-05-13 20:16:13.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:17:10.0 Time in seconds: 57 seconds.
    57
    GPSTime 2010-05-13 20:18:10.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:19:10.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:20:10.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:21:11.0 Time in seconds: 61 seconds.
    61
    GPSTime 2010-05-13 20:22:11.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:23:11.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:24:11.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:25:11.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:26:11.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:27:11.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:28:12.0 Time in seconds: 61 seconds.
    61
    GPSTime 2010-05-13 20:29:12.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:30:12.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:31:12.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:32:12.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:37:46.0 Time in seconds: 334 seconds.
    34
    GPSTime 2010-05-13 20:38:46.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 20:47:22.0 Time in seconds: 516 seconds.
    36
    GPSTime 2010-05-13 21:12:54.0 Time in seconds: 1532 seconds.
    32
    GPSTime 2010-05-13 21:13:54.0 Time in seconds: 60 seconds.
    60
    GPSTime 2010-05-13 21:14:55.0 Time in seconds: 61 seconds.
    61
    GPSTime 2010-05-13 21:37:08.0 Time in seconds: 1333 seconds.
    13
    GPSTime 2010-05-13 21:38:09.0 Time in seconds: 61 seconds.
    61
    31169.0
    08:39:29 hh:mm:ssi am getting the total time for all date
    i need only the particular date of total time
    2010-05-11-->total time
    2010-05-12->Total time
    2010-05-13->total time
    how do i change the given code to get the above output
    please help me anybody having idea

    Bakthavachalam wrote:
    i am getting the total time for all date
    i need only the particular date of total timeIn which case your while(rs.next()) loop needs to process 1 day at a time and print its results when the date changes (assuming your Timestamps come in in date sequence; if not, you'll have to sort them first).
    I suspect you'll also have to decide what you want to do with
    GPSTime 2010-05-13 23:59:59.0
    followed by
    GPSTime 2010-05-14 00:00:01.0
    Do you still need to calculate the difference? And if so, which "date" does it go in, or is it split?
    Your logic seems incredibly convoluted for such a simple task. What exactly are you trying to do?
    Winston
    BTW: TimeStamp.getSeconds() is deprecated, which means you use it at your peril.

  • How to get the date of the last transaction in a mounted standby database?

    Hello,
    Could you tell me how to get the date of the last transaction recorded in a MOUNTED standby database?
    The following query doesn't work...because the database is not open...
    select scn_to_timestamp(current_scn) from v$database;
    Thanks

    Hi,
    You should be able to run the following command in mounted mode on standby database.
    select current_scn from v$database;
    then run the following to convert it to timestamp.
    select scn_to_timestamp(99999999) from dual; *<-- Replace here the SCN value you got above. This needs to be run on the primary database due to standby database in mount mode.*
    Alternatively you can also check at the alert.log file to find the last scn which has been applied.
    Regards
    Edited by: skvaish1 on Jan 19, 2010 11:15 AM

  • How do I get the date of a file in an FTP?

    As stated in the subject.
    I am at wits end trying to get the date of a file from FTP(Stuck for days).
    I tried the "URLConnection" Class but could only get me the size of the file with "getContentLength()"
    "getContentDate()" & "getLastModified()" both give me a 0. They only works for files on HTTP but not FTP.
    Anyone has any simple solution on how to get the date of a file on FTP?
    Thanks in Advance.

    The FTP specification has long awaited the magical file meta-data access protocol, which never came. There is no FTP defined manner to obtain the date of a file. The common work-around is to get the containing directory list and <shudder> parse the format of the returned text for the target file and date. Since there is no standard directory listing format, there is no guarantee that you will be able to get that date, and your application would have to cry to the user for help.
    Some FTP applications, in addition to providing parsers for Unix/Linux and DOS/Windows directory list formats, also provide the user with a format definition script to parse whatever the user encounters.
    I hope you find this of some help.

Maybe you are looking for