Java converts wrong Timestamp

The following code return the same date.
          SimpleDateFormat formater = new SimpleDateFormat();
             formater.applyPattern("yyyy-MM-dd hh:mm");
             Timestamp ts = null;
             try {
               ts = new Timestamp (formater.parse("2006-10-10 12:00").getTime());
               System.out.println(ts);
               ts = new Timestamp (formater.parse("2006-10-10 00:00").getTime());
               System.out.println(ts);
          } catch (ParseException e) {
               e.printStackTrace();
          }If you see I have put different hour 12:00 and 00:00. I need both in the database. System.out prints:
2006-10-10 00:00:00.0
2006-10-10 00:00:00.0So, I have only 23 Hours a day, instead of 24.
What was my mistake?

Note the difference between h and H in the formatting characters.

Similar Messages

  • How to convert oracle timestamp to java timestamp

    Hi,
    I need to convert oracle timestamp that i got from oracle database to java timestamp.I tried to use getTimestamp() to get timestamp value from oracle, but am getting NumberFormatException.
    Could any of suggest how to convert oracle timestamp to java timestamp.

    Thanks jverd ,
    then my code will be like:
    String oracleTS="11-MAR-05 11.19.20.625 AM";
    // am looking for yyyy-MM-dd HH:mm:ss format
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd
    HH:mm:ss");           
    Timestamp javaTimestamp=Timestamp.valueOf(oracleTS);
    System.out.println("javaTimestamp----->>
    "+javaTimestamp);
    ving java.lang.NumberFormatException: For input
    string: "MAR"Well, the SimpleDateFormat has to actually match the format you're trying to parse, for one thing. Then you have to actually USE the SDF, which you didn't.
    You really haven't made it clear what you're trying to do, and it doesn't appear that you bothered to study the links I provided.
    DateFormat df = new SimpleDateFormat("dd-MMM-yy HH.mm.ss.SSS aa");
    Date date = df.parse(oracleTS);
    Timestamp ts = new Timestamp(date.getTime());

  • Converting sql timestamp into a usable java format??

    hi there.
    does anyone know how to convert an sql timestamp into a usable java format? i have retrieved a timestamp from a mysql table in a jsp script and would like to convert it into the following format:
    12:42pm | 08.07.02
    as i understand it, i'll need to convert the timestamp into seconds since 1970 and then manipulate it as a calendar object? my first line is working, but i don't know what to do after...
    java.sql.Timestamp sqlTimestamp = resultSet.getTimestamp("date_and_time");
    next...?
    any help would be much appreciated!!
    thanks.

    please excuse my java sytnax ignorance, but i've tried a bunch of different syntax arrangements and can't figure out how to use the getTime() method. what comes after my first line there?
    java.sql.Timestamp sqlTimestamp = resultSet.getTimestamp("date_and_time");
    then something like:
    long msec=date.getTime(sqlTimestamp);
    but that doesn't seem to work...
    thanks for any help!

  • Anybody know of a method to convert a timestamp to a Nanosec equivalent?

    Does anybody know of a method to convert a timestamp object to a nanosecond equivalent since 1970?
    Thanks

    By a timestamp object you mean an instance of the class java.sql.Timestamp, right? Then the following will give you the nanoseconds:
    long nanos = stamp.getTime()*1000000 + stamp.getNanos();

  • How to convert normal timestamp to julian timestamp in oracle

    Hi Friends
    How can i convert normal timestamp to Julian Timestamp in Oracle ?
    Thanks for your help

    Hi Chris,
    I dont have any idea on this. But need clarification on your query.
    When I executing below query I'm getting same output. 'J' will give only Julian day right not the timestamp. Please correct me if I am wrong.
    SQL> select to_char(systimestamp,'J') J,to_char(sysdate,'J') from dual;
    J            TO_CHAR
    2456631   2456631
    http://en.wikipedia.org/wiki/Template:JULIANDAY.TIMESTAMP

  • How to convert a timestamp to date/time in CDS View?

    Dear experts,
    I would like to convert a timestamp to a date and time within a CDS view.
    This is what I tried to do:
    Cast (Cast(<timestamp> as abap.dec(8,0)) as abap.dats) as <date>
    I also thought about first converting the timestamp into a plain numerical character, then using substring and then casting it to abap.dats. Then its giving me an error that says: "dec can't be converted into numc".
    The above written code also throws an error - "function not allowed/ no cast within a cast".
    It is quite nasty not being able to write a cast within a cast - how else am i supposed to achieve a date here?
    I am looking forward to have your answers!
    Thanks and BR
    Anja

    Hi Anja,
    what you try to do is currently not possible, a feature not available in CDS views.
    Yet it surely is a feature, ABAP developers would like to see on the feature request list .
    Cheers,
      Jasmin

  • VB to Java Converter

    Help! I am looking for a Visual Basic to Java Converter. Can anyone recommend a good site, product or resource?

    As far as I know, this is the best VB to Java converter:
    http://www.tvobjects.com/products/Convert-VB-to-Java.html

  • Can Java convert text in to three dimensional forms?

    Hi,
    I'm an MA student at Central Saint Martins College of Art and Design in London. I'm currently working on a project to convert text, entered onscreen by users, into three dimensional forms when initiated by clicking on a button. Each 3D form is to be unique to the text entered. Does anyone know how best to do this and whether Java is the best tool for this? Any help or ideas that can be offered will be greatly appreciated.
    Thanks

    Hi,
    Thank you for your help, the link is a great starting point in the development of my project, but its not the "nail on the head", which is my fault. On reading back my last posts it seems I omitted a key word (sorry, my mistake) in the description of what I want to do, which is: "…can Java convert text into abstract three dimensional forms?" By abstract three dimensional forms I was hoping to create something along the lines of what is possible with Rhinoscript, here is an example of the type of visual I want to be able create from the transformation of user entered text using computer code: http://www.theverymany.net/uploaded_images/080108_Srf_Test001_01_k_TVM-718625.jpg. I hope this sheds some light on the direction I'm hoping to take, so if you or anyone else can offer any more help or pointers I will be eternally grateful.
    Thanks

  • Converting Oracle TIMESTAMP(4) column to SQL datetime column conversion error in ssis

    I could not able to convert Oracle TIMESTAMP(4) column to SQL datetime column conversion error in ssis.
    I'm connecting OLEDD Oracle Source to OLEDB SQL Destination in SSIS package. I'm trying to insert data from oracle datetime column into sql datetime column. I'm getting some errors.
    Please provide helpful info.

    You can transform the data types directly at the source by writing a proper SQL statement, or you can convert them using the data conversion component.
    Please refer the below link
    http://stackoverflow.com/questions/6256168/how-to-convert-a-timestamp-in-string-format-to-datetime-data-type-within-a-packa

  • Need help with error java.lang.IllegalArgumentException: timestamp on bar b

    My company uses Java based applications for real time streaming stock market information and I have come across 2 users that are generating the same error:
    Bar.addBar failed adding com.abwg.bar.BasicBar 20071210-08:27:00.000 104.34 104.35 104.25 104.25 950 to com.abwg.bar.BasicBar 20071210-09:30:00.000 104.11 104.38 104.11 104.38 436 :java.lang.IllegalArgumentException: timestamp on bar being combined older than original bar
    I have had no luck trying to determine what the cause of this error is, however both users experience very laggy performance shortly after launching the application. I have not been able to duplicate the problem, and the developers have not been able to provide any response or possible causes yet.
    I'd be very appreciative if anyone could help me make some sense of what this error type might mean. It's got something to do with the computer that the application is being run on. One user is on a Mac 10.3 using J2SE 1.4.2_12 and the other is on Win XP using Java 1.6_3

    Thank you Frank and Carole for your response. The stated issue/error is resolved. It had to do with the upgrade somehow which lead to multiple certs for the same agent. Anyway, I had to delete ADS and all attached Agents,  re-create ADS, re-create all Agents and re-register with the new ADS. I then manually re-registered the Directory Server instances on both the Primary and Secondary Servers with the new ADS. Voila, the DSCC Web console no longer prompts for server credentials.
    But importing the Wild card cert issue still remains. I added the issuing CA chain to the ldap instance CA store and I see the certs listed. But when I try to import the P12 cert/key combo, I get an error which says something like: "The certificate is already in the database". But it is not, verified using certutil.
    Yes internal CA or Self-signed Certs are fine. If I add the internal CA and Root CA to the cert store on my LDAP clients, then I am fine. No SSL errors. But want to avoid using such as we do have quite a few clients which would be connecting to the store. Hence want to use our  enterprise wild card Cert. I am not sure if it is an issue importing a wild card pkcs12 format.
    As mentioned above I did add the CA chain (which issued the wild card) to the actual instance, not the ADS. I can try that. But are you sure we need to add the Root CA to Tomcat ks.
    And while we are at it, the Self-signed certs generated using the Console is only valid for 2 years. Is it possible to change the term ?
    Thanks again.

  • Converting a timestamp field from GMT to EST

    Hi
    I have to convert the timestamp field coming from the source from GMT to EST.
    CREATE TABLE X
    TS_FIELD TIMESTAMP(6)
    INSERT INTO X VALUES('07-JAN-13 02.00.06.597000 PM');
    INSERT INTO X VALUES('07-FEB-13 02.00.06.676000 PM');
    INSERT INTO X VALUES('07-MAR-13 12.36.14.260000 PM');
    INSERT INTO X VALUES('07-APR-13 12.36.56.713000 PM');
    INSERT INTO X VALUES('07-MAY-13 03.46.48.800000 AM');
    I need to convert the above timestamp field from GMT to EST in 24hour format.
    I tried it doing,but I am getting hours conflict with the day error.
    I have tried the below one and milliseconds being set to zero's
    select X,
    TO_timestamp(TO_CHAR(CAST(FROM_TZ(CAST(TO_DATE(TO_CHAR(X,'YYYY-MM-DD HH24:MI:SS.SSSSS')
    ,'YYYY-MM-DD HH24:MI:SS.SSSSS')
    AS TIMESTAMP),'GMT') AT TIME ZONE 'US/EASTERN' AS DATE),'YYYY-MM-DD HH24:MI:SS.SSSSS'),'YYYY-MM-DD HH24:MI:SS.SSSSS')
    FROM X
    Please help me in this regard.I am trying in parallel as well.
    Thanks in advance
    KVB

    Not clear what are you trying to achieve..Why are you casting as DATE?
    SQL>  select ts_field,
      2          cast(from_tz(ts_field,'GMT') AT TIME ZONE 'EST' as timestamp) t
      3   FROM X;
    TS_FIELD                                                                    T
    07-JAN-13 02.00.06.597000 PM                                                07-JAN-13 09.00.06.597000 AM
    07-FEB-13 02.00.06.676000 PM                                                07-FEB-13 09.00.06.676000 AM
    07-MAR-13 12.36.14.260000 PM                                                07-MAR-13 07.36.14.260000 AM
    07-APR-13 12.36.56.713000 PM                                                07-APR-13 07.36.56.713000 AM
    07-MAY-13 03.46.48.800000 AM                                                06-MAY-13 10.46.48.800000 PM

  • [ASK]Bugs of Java or Wrong Code?

    Dear All,
    What this is bugs of Java or me not to understand java programming, this my piece code :
    String kode = txtKode.getText();
            String nama = inputNama.getText();
            String keterangan = inputKeterangan.getText();
            try {
                Connection c = KoneksiMySql.getKoneksi();
                String sql = "UPDATE UNIT SET NAMA=?, KETERANGAN=?, WKT_INPUT=now() WHERE KODE=?";
                PreparedStatement p = c.prepareStatement(sql);
                p.setString(1, nama);
                p.setString(2, keterangan);
                p.setString(3, kode);
                p.executeUpdate();
                p.close();
                JOptionPane.showMessageDialog(null, "Data Berubah",
                        "Pemberitahuan", JOptionPane.INFORMATION_MESSAGE);
            } catch(SQLException e) {
                System.out.println("Error : " + e);
                JOptionPane.showMessageDialog(null, "Proses Rubah Unit Gagal",
                        "Pesan Error", JOptionPane.ERROR_MESSAGE);      
            }finally {
            inputNama.setText(null);
            inputKeterangan.setText(null);
                btnTambah.setEnable(true);
                btnHapus.setEnabled(false);
                btnRubah.setEnabled(false);
                inputNama.requestFocus();
    JOptionPane is Show and no error appears but data in database does not change, and code in block finally not executed.
    i'm use jInternalFrame, first run Only 'Add Button, Search Button' enable and other button are disable, then when 'Search Button' is clicked and open other jInternalFrame and get data form database, 'Add button' Disable and 'Delete Button, Change Button' are Enable. that my piece code on Change Button ActionPerformed.
    Please it's support.
    Thanks,
    Best & Regrads.

    Cross posted
    [ASK]Bugs of Java or Wrong Code?
    [HELP]Bugs of Java or Wrong Code?
    db

  • Mails in Mail have wrong Timestamp

    Hello Communitiy
    I had a problem with my Mail, the Mails weren't downloaded, so i decided to rebuild the Index with "Mailbox > Recovery". After the rebuild, 50% of my Mails had a wrong Received Timestamp (the Timestamp from 50% of the Mails where set to the Timestamp where the rebuilding Process finished).
    I tried to recover my System from a TimeMachine Backup, but I had no lick. After opening Mail the first time, the rebuild/index process started, and again 50% of the Mails the Timestamp was set to the Timestamp after the Indexin-Process finished.
    I found in the Logs following entry:
    30.01.14 06:59:50.883 Mail[3607]: Unable to parse date: "So Okt 02 08:03:17 2011"
    Stripped string: "So Okt 02 08:03:17 2011"
    Can anyone help me?
    Best Regards
    Patrick

    i'm having similar issue.  huge amounts of my "archived" mail are now have a recent date incorrectly applied.  
    the problem is pretty easy to reproduce and demonstrate in mavericks.   for example, if you dig down into one of the mailbox folders until you find files containing individual message (.emlx files), you can preview them (with quick look - i.e., space bar in the finder).   this will generate a parse error viewable in console.   the preview of the message shows it has having no date.    inspection of the text file shows a date header like this: "Date: Thu Feb 13, 2003  5:22:20 PM US/Eastern", which to my eye appears to be out of spec wrt RFC 2822.   
    according to that spec, allowable time zone specs are of the form of the GMT offset expressed as a string consisting  of a '+' or '-' followed by a four digit offset.    there is also legacy support for "obsolete" timezone specs of certain legacy timezone formats such as "EST", etc. but not a full string like "US/Eastern".   also the standard does not seem to allow 12-hour time format, nor a single-digit hour format.  thus "5:22:20 PM" is not allowed and should instead be written as "17:22:20". 
    the mail in question may have originated on some other system.   it was likely originated on a non-mac system.   however, i know that the same files were handled correctly by earlier versions of mail.app (than my current version, 7.3).  
    i will probably try using a perl script or something to go through and re-write the dates to conforming values, then see if doing a "rebuild" would correct the problem.   shouldn't be necessary to do this, however.   within reason, i think no version of apple mail should ever fail to process an earlier version of apple mail's files.   apple should have plenty of data to use for regression testing this kind of stuff.    if they are going to break compatibility, then they should provide a translator or import utility or something rather than just leaving people hanging. 
    the irony is that when i encountered this bug, i was trying to bring in mail not from some old dusty osx box from 2001, but instead from  5-day old backups of my current/personal machine that i just lost, also running the latest versions of mavericks/mail.   

  • Using CAST function to convert to timestamp

    I have a select statement that runs via JDBC and is not using any index as timestamp is explicitly used. I would like to be able to convert to Date so the proper index can be used as this column is of Date datatype. I'm having "ORA-25137: Data value out of range" when I use "b.TRAN_DATE BETWEEN CAST(:1 AS DATE) AND CAST(:2 AS DATE) : instead of "b.TRAN_DATE BETWEEN :a and :b.
    Could someone help with this as I really want our indexes to be used and therefore Date datatype should be used in the JDBC connection
    Thanks

    Below is the query that is not using the index b/c of the date datatype. Changing b.TRAN_DATE BETWEEN :1 AND :2 to b.TRAN_DATE BETWEEN CAST(:1 AS DATE) AND CAST(:2 AS DATE) gives "ORA-25137: Data value out of range" error.
    SELECT
    a.CURRENCY_ID D_161,
    a.CURRENCY_NAME D_201,
    b.TRANS_TYPE_NAME D_22,
    UPPER(b.TRANS_TYPE_NAME) S_22,
    REPORT.MASK_CARD(b.CARD_NUMBER, b.TRANS_TYPE_ID) D_142,
    REPORT.MASK_CARD(UPPER(b.CARD_NUMBER), b.TRANS_TYPE_ID) S_142,
    b.TRAN_DATE D_440,
    b.VEND_COLUMN D_54,
    UPPER(b.VEND_COLUMN) S_54,
    c.LOCATION_NAME D_16,
    UPPER(c.LOCATION_NAME) S_16,
    d.EPORT_SERIAL_NUM D_60,
    UPPER(d.EPORT_SERIAL_NUM) S_60,
    b.DESCRIPTION D_58,
    UPPER(b.DESCRIPTION) S_58,
    SUM(b.TOTAL_AMOUNT) D_51_SUM,
    a.CURRENCY_SYMBOL D_181,
    SUM(b.QUANTITY) D_55_SUM,
    a.CURRENCY_CODE D_182
    FROM
    CORP.CURRENCY a,
    REPORT.ACTIVITY_REF b,
    REPORT.EPORT d,
    REPORT.LOCATION c,
    REPORT.TERMINAL f,
    REPORT.VW_USER_TERMINAL e
    WHERE ((b.TRAN_DATE BETWEEN :1 AND :2
    AND b.CARD_NUMBER = :3)
    AND e.USER_ID = :4)
    AND b.CURRENCY_ID = a.CURRENCY_ID
    AND b.EPORT_ID = d.EPORT_ID
    AND b.LOCATION_ID = c.LOCATION_ID
    AND f.TERMINAL_ID = e.TERMINAL_ID
    AND b.TERMINAL_ID = f.TERMINAL_ID
    GROUP BY
    a.CURRENCY_ID,
    a.CURRENCY_NAME,
    b.TRANS_TYPE_NAME,
    UPPER(b.TRANS_TYPE_NAME),
    REPORT.MASK_CARD(b.CARD_NUMBER, b.TRANS_TYPE_ID),
    REPORT.MASK_CARD(UPPER(b.CARD_NUMBER), b.TRANS_TYPE_ID),
    b.TRAN_DATE,
    b.VEND_COLUMN,
    UPPER(b.VEND_COLUMN),
    c.LOCATION_NAME,
    UPPER(c.LOCATION_NAME),
    d.EPORT_SERIAL_NUM,
    UPPER(d.EPORT_SERIAL_NUM),
    b.DESCRIPTION,
    UPPER(b.DESCRIPTION),
    a.CURRENCY_SYMBOL,
    a.CURRENCY_CODE
    ORDER BY
    D_161 ASC,
    D_201 ASC,
    S_22 ASC,
    S_142 ASC,
    D_440 ASC,
    S_54 ASC,
    S_16 ASC,
    S_60 ASC,
    S_58 ASC,
    D_51_SUM ASC,
    D_181 ASC,
    D_55_SUM ASC,
    D_182 ASC

  • Convert MySQL timestamp field to a Unix timestamp

    I have a process where I want to compare the current date with an expiration date that is so many months after a registration date. The registration date is stored in a MySQL timestamp format. I want to convert this to a Unix timestame so I can do the comparison with Time(). I have tried both the MySQL UNIX_TIMESTAMP and the PHP getTimestamp() functions and cannot get them to work. I have tried UNIX_TIMESTAMP both in  the original SELECT statement and as a stand alone one. I also get a divide-by-zero error with the date_default_timezone_set function. I have enclosed screenshots of the code and the result of the echo at the bottom. THANKS!

    You're making it far too complicated.
    SELECT TO_DAYS(reg_date) - TO_DAYS(CURDATE()) AS daysleft
    FROM ssregis
    WHERE. . .
    That will give you the number of days left until the registration expires. If it's less than 0, redirect to the renewal page.
    By the way, you're laying yourself wide open to SQL injection attacks by failing to escape the input from the query string. At the very least, you should be doing this:
    $entered_ss_id = mysql_real_escape_string($_GET['record_id']);
    $entered_email = mysql_real_escape_string($_GET['email_address']);
    However, since it looks as though you're hand-coding the script, you should be using MySQL Improved rather than PHP's deprecated MySQL functions. See http://docs.php.net/manual/en/mysqlinfo.api.choosing.php.

Maybe you are looking for

  • Need information on Scenarios

    Hi Gurus, Could you please provide any link or information on the below mentioned scenarios. 1)Agency commisions 2)Sales from warehouses 3)Direct sales. Thanks Hari Challa.

  • Errors when starting JMS Server

              When trying to start my managed server (after deployment) I get the following error:           Throwable: java.util.ConcurrentModificationException Exception raised: java.util.ConcurrentModificationException           java.util.ConcurrentMo

  • Wrt54gs router help

    can someone please help? got a desktop pc on xp, a laptop on vista,no problems connecting desktop, heres the puzzling bit,reset modem and router desktop and laptop connect wired through router,then connect wireless through router no problem,(still co

  • SETTING TEXTFIELD IN DIFFERENT CLASS

    I have 2 classes: class1, class2. In class2 I have a textfield. In class1 I am trying to set the textfield in class2 with text: class2.textField_name.setText(string). This does not work - null pointer exception???

  • Search Form with UIX

    Hi all, is it possible in a search form with uix shows always the edit criteria with execute button and not when I click the find button? Please help!!! Matteo.