Converting value from System.currentTimeMillis() to readable format

hi
i have in database coumn with values that were stored as result of executing System.currentTimeMillis() in java (=“the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC). i need to convert these values to some human readable format.
i am able to get year, month and day from these values(value_date) in format "dd/mm/yyyy" but i need hours, minutes and seconds as well.
select i have for getting years, months and days:
select (
extract (day FROM (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
|| '/'||
extract (month from (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
||'/'||
extract (year FROM (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
FROM some_table;
please advice how to improve this select to get something like "dd/mm/yyyy hh:mm:ss"
thanks

Note that the result with to_char might still not be what you expect (due to timezone and/or DTS):
SQL>  CREATE OR REPLACE FUNCTION currenttimemillis
   RETURN NUMBER
IS
   LANGUAGE JAVA
   NAME 'java.lang.System.currentTimeMillis() return java.lang.long';
Function created.
SQL>  select to_char(sysdate, 'dd.mm.rrrr hh24:mi:ss') dt,
       to_char(date '1970-01-01' + currentTimeMillis/(1000*24*60*60),'dd.mm.rrrr hh24:mi:ss') dt2
  from dual
DT                  DT2               
04.06.2009 16:44:09 04.06.2009 14:44:09

Similar Messages

  • When I convert documents from pages to word, the format is changed partially and at times entirely. Any solution for this?

    When I convert documents from pages to word, the format is changed partially and at times entirely. Any solution for this?

    Gig Harbor Tina wrote:
    ...Is it possible that the server at work is somehow affecting these attachments?
    I can't say, but if that's the answer, trying to get it fixed might be impossible. Instead, I'd suggest compressing your attachments to create a .zip file. Decompression at the other end would take no time, and if the server changes the attachment's file type, just change it back to .zip.

  • How to convert value from exp. value to double/float???

    Hi all,
    I am fetching values from database, which is of type double / float.
    eg. values will be like -22,777,548 will be stored in database.
    NOw if i use
    float a= rs.getFloat(1);
    out.println("a="+a);
    I get output as a= -2.2777548E7
    I want to remove "E" from out put value and display as it was given in DB.
    How to solve this problem?
    Please Help!
    Regards
    Ashvini

    What do you mean - 'how does it work' ? All format classes (MessageFormat, DecimalFormat , SimpleDateFormat etc) are used to convert data from one form to other. Go through the java.text.* api. They work based on some pattern searches, pattern matches etc - dont know in detail :)
    As for the other things, thanks :)
    cheers,
    ram.

  • Get agent "run as" value from system tables

    Hi, 
    When you create a job step (specifically an SSIS) you can set the "run as" value.  Can anyone tell me where this value can be queried in system tables/views? 
    I'm looking in 
    SELECT * FROM msdb..sysjobsteps
    SELECT * FROM msdb..sysjobs
    but can't see the value I know the job step is set to. 

    Try the below:
    SELECT
    B.[job_id] AS [JobID]
    , B.[name] AS [JobName]
    , A.[step_name] AS [StepName]
    , C.[name] AS [RunAs]
    FROM
    [msdb].[dbo].[sysjobsteps] AS A
    INNER JOIN [msdb].[dbo].[sysjobs] AS B ON A.[job_id] = B.[job_id]
    LEFT JOIN [msdb].[dbo].[sysproxies] AS C ON A.[proxy_id] = C.[proxy_id]
    ORDER BY [JobName]

  • Convert data from ANSI to UTF-8 format

    Hello,
    We have data in ANSI format (binary) which we need to convert into UTF-8 format. We are able to do it using FM's GUI_UPLOAD and GUI_DOWNLOAD but as the amount of data is huge we are planning to get the conversion done using background job. But, we are not able to get it yet. Can anybody suggest ways to resolve this? Can class CL_ABAP_CONV_X2X_CE be used for the same?
    Thanks...
    With Regards,
    Mukul Kulkarni

    Hello,
    If you have the data in Binary mode, you can use the addition IN BINARY MODE while uploading.
    For downloading in UTF-8, you can use the addition TEXT MODE ENCODING UTF-8.
    BR,
    Suhas

  • Fm to convert time from 12 hour to 24 hour format?

    Hi Gurus,
    Can you please tell me the Funtion module for converting time from 12 to 24 hour format and how to use that, kindly provide some test data too.
    THanks and Regards
    Sudipto

    Hi,
    You can use FM HRVE_CONVERT_TIME to convert time to 24 hour format.
    Pass B in TYPE_TIME parameter and time you wish to convert to along with AM/PM in INPUT_AM_PM parameter.
    Regards,
    Ni3

  • How to read from BLOB and Write to a file in user readable format.

    Hi,
         I am trying to read from a BLOB column and write the content to a file in user readable format. So far I was able to read the Blob column using dbms_lob, but not able to write to a file. Kindly let me know the method to do this.

    Hi, with this Java Code from Oracle Technet it's a easy thing:
    // classpath= /ORACLE/u01/app/oracle/product/10.2.0.3/jdbc/lib/ojdbc14.jar
    // Java SQL classes
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    // Oracle JDBC driver class
    import oracle.jdbc.OracleDriver;
    // Java IO classes
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    //Java Util classes
    import java.util.Properties;
    * This class demonstrates the Oracle JDBC 10g enhanced features for inserting
    * and retrieving CLOB data from the database. Using the new features, large
    * data of more than 32765 bytes can be inserted into the database using the
    * existing PreparedStatement.setString() and PreparedStatement.getString()
    * methods.
    public class ClobMan {
    /* Database Connection object */
    private Connection conn = null;
    /* Variables to hold database details */
    private String url = null;
    private String user = null;
    private String password = null;
    // Create a property object to hold the username, password and
    // the new property SetBigStringTryClob.
    private Properties props = new Properties();
    /* String to hold file name */
    private String fileName = null;
    * Default Constructor to instantiate and get a handle to class methods
    * and variables.
    public ClobMan(String fileName) {
    this.fileName = fileName;
    * Main runnable class.
    public static void main(String[] args) throws SQLException {
    // Instantiate the main class.
    ClobMan clobMan = new ClobMan(args[0]);
    // Load the Oracle JDBC driver class.
    DriverManager.registerDriver(new OracleDriver());
    // Load the database details into the variables.
    String dbUrl = "jdbc:oracle:thin:@pmol:1550:dbpmol";
    clobMan.url = dbUrl;
    clobMan.user = "gh10";
    clobMan.password = "secret";
    // Populate the property object to hold the username, password and
    // the new property 'SetBigStringTryClob' which is set to true. Setting
    // this property allows inserting of large data using the existing
    // setString() method, to a CLOB column in the database.
    clobMan.props.put("user", clobMan.user );
    clobMan.props.put("password", clobMan.password);
    clobMan.props.put("SetBigStringTryClob", "true");
    // Check if the table 'CLOB_TAB' is present in the database.
    //clobMan.checkTables();
    // Call the methods to insert and select CLOB from the database.
    //clobMan.insertClob();
    clobMan.selectClob();
    * This method will insert the data into a CLOB column in the database.
    * Oracle JDBC 10g has enhanced the existing PreparedStatement.setString()
    * method for setting the data more than 32765 bytes. So, using setString(),
    * it is now easy to insert CLOB data into the database directly.
    private void insertClob() throws SQLException {
    // Create a PreparedStatement object.
    PreparedStatement pstmt = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create SQL query to insert data into the CLOB column in the database.
    String sql = "INSERT INTO clob_tab VALUES(?)";
    // Read a big file(larger than 32765 bytes)
    String str = this.readFile();
    // Create the OraclePreparedStatement object
    pstmt = conn.prepareStatement(sql);
    // Use the same setString() method which is enhanced to insert
    // the CLOB data. The string data is automatically transformed into a
    // clob and inserted into the database column. Make sure that the
    // Connection property - 'SetBigStringTryClob' is set to true for
    // the insert to happen.
    pstmt.setString(1,str);
    // Execute the PreparedStatement
    pstmt.executeUpdate();
    } catch (SQLException sqlex) {
    // Catch Exceptions and display messages accordingly.
    System.out.println("SQLException while connecting and inserting into " +
    "the database table: " + sqlex.toString());
    } catch (Exception ex) {
    System.out.println("Exception while connecting and inserting into the" +
    " database table: " + ex.toString());
    } finally {
    // Close the Statement and the connection objects.
    if (pstmt!=null) pstmt.close();
    if (conn!=null) conn.close();
    * This method reads the CLOB data from the database by using getString()
    * method.
    private void selectClob() throws SQLException {
    // Create a PreparedStatement object
    PreparedStatement pstmt = null;
    // Create a ResultSet to hold the records retrieved.
    ResultSet rset = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create SQL query statement to retrieve records having CLOB data from
    // the database.
    String sqlCall = "SELECT rownum, name, sourcetext FROM t_source";
    pstmt= conn.prepareStatement(sqlCall);
    // Execute the PrepareStatement
    rset = pstmt.executeQuery();
    String rownum = null;
    String o_name =null;
    String clobVal = null;
    // Get the CLOB value from the resultset
    //java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter("pr_all.sql"));
    while (rset.next()) {
    rownum = rset.getString(1);
         o_name = rset.getString(2);
         clobVal = rset.getString(3);
    System.out.println(" length: "+clobVal.length()+" "+o_name+" "+rownum);
         java.io.BufferedWriter out =
         new java.io.BufferedWriter(new java.io.FileWriter(o_name+".prc"));
         out.write(clobVal);
         out.newLine();
         out.write("/");
         out.newLine();
         out.newLine();
    out.flush();
    out.close();
    } catch (SQLException sqlex) {
    // Catch Exceptions and display messages accordingly.
    System.out.println("SQLException while connecting and querying the " +
    "database table: " + sqlex.toString());
    } catch (Exception ex) {
    System.out.println("Exception while connecting and querying the " +
    "database table: " + ex.toString());
    } finally {
    // Close the resultset, statement and the connection objects.
    if (rset !=null) rset.close();
    if (pstmt!=null) pstmt.close();
    if (conn!=null) conn.close();
    * Method to check if the table ('CLOB_TAB') exists in the database; if not
    * then it is created.
    * Table Name: CLOB_TAB
    * Column Name Type
    * col_col CLOB
    private void checkTables() {
    Statement stmt = null;
    ResultSet rset = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create Statement object
    stmt = conn.createStatement();
    // Check if the table is present
    rset = stmt.executeQuery(" SELECT table_name FROM user_tables "+
    " WHERE table_name = 'CLOB_TAB' ");
    // If the table is not present, then create the table.
    if (!rset.next()) {
    // Table does not exist, create it
    stmt.executeUpdate(" CREATE TABLE clob_tab(clob_col CLOB)");
    } catch (SQLException sqlEx) {
    System.out.println("Could not create table clob_tab : "
    +sqlEx.toString());
    } finally {
    try {
    if( rset != null ) rset.close();
    if( stmt != null ) stmt.close();
    if (conn!=null) conn.close();
    } catch(SQLException ex) {
    System.out.println("Could not close objects in checkTables method : "
    +ex.toString());
    * This method reads the specified text file and, returns the content
    * as a string.
    private String readFile()
    throws FileNotFoundException, IOException{
    // Read the file whose content has to be passed as String
    BufferedReader br = new BufferedReader(new FileReader(fileName));
    String nextLine = "";
    StringBuffer sb = new StringBuffer();
    while ((nextLine = br.readLine()) != null) {
    sb.append(nextLine);
    // Convert the content into to a string
    String clobData = sb.toString();
    // Return the data.
    return clobData;
    }

  • Converting from milliseconds to a date format in java

    This so that, that date can be inserted into a date column in mysql
    What I have is something like 1119193190
    I do:
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
    Date resultdate = new Date(yourmilliseconds);
    System.out.println(sdf.format(resultdate));
    and Java gives me something like:
    Jul 04,2004 14:06
    But Java then when inserting into a mysql table is all like um....no:
    com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: 'Jul 04,2004 14:06' for column 'prodDate' at row 1
    proDate is of type date in mysql.
    Help?

    jverd wrote:
    "Jul 04,2004 14:06" is a String, not a Date.
    PreparedStatement ps = conn.prepareStatement("insert into T(name, birthdate) values(?, ?)");
    ps.setString(1, "Joe Smith");
    java.sql.Date date = new java.sql.Date(yourmillis);
    ps.setDate(2, date);
    ps.executeUpdate();
    I am a bit confused
    This i what I have
    for(int i = 0; i < productions.size(); i++)
                        //Create a new Production from the ArrayList
                        Production p = (Production) productions.get(i);
                        //Convert the date from milliseconds to YYYY-MM-DD format. for mysql?
                        SimpleDateFormat dateFormatter = new SimpleDateFormat("MMM dd,yyyy HH:mm");
                        Date convertedDate = new Date(p.getDate());
                        //Build a query to insert the Production into the table
                        String insertQuery = "INSERT INTO WELL_PROD VALUES(" +
                                  "'" + p.getLocation() + "'," +
                                  "'" + dateFormatter.format(convertedDate) + "'," +
                                  "'" + p.getOilProd() + "'," +
                                  "'" + p.getWaterProd() + "'," +
                                  "'" + p.getGasProd() + "')";
                        //Print the query to the screen
                        System.out.println("-> INSERTING the following query into well_prod: ");
                        System.out.println("   " + insertQuery);
                        //Update the database using the constructed query
                        int result = statement.executeUpdate(insertQuery);
                        //Print out the result of the insertion
                        System.out.println("   INSERT RESULT: " + result);
                   }Are you saying something like
    java.sql.Date date = new java.sql.Date(Something , what I have no idea, Should go here);
    instead of
    SimpleDateFormat dateFormatter = new SimpleDateFormat("MMM dd,yyyy HH:mm");
    and then carry on as normal?
    If so, what should go in those brackets based on the code?
    java.sql.Date date = new java.sql.Date("MMM dd,yyyy HH:mm");
    This is all being read in from a text file and converted over before being spit out to the data base, it all works except for the date...

  • System.currenttimemillis() returns value ..can't decode it

    Does System.currenttimemillis() return milli seconds elapsed after Jan 1, 1970... does it have no relation with our current time...
    When i did it and print it out .. my millis were the last 3 digits and secs were the 2 dgits before miiliseconds..
    eg: XXXXXXXssmmm
    or was it just a mere coincidence...very confused..

    I was always taught to use Calendar to access individual fields (and DateFormats for formatting and parsings). One reason you aren't supposed to just take the timestamp value (System.currentTimeMillis()) is that there are complications: for example, because of Earth's wobbly orbit there are things called "leap seconds" that may be added to years, so you can't assume each day consists of exactly 24*60*60 seconds (even ignoring DST). But then I wrote this code:
    import java.text.*;
    import java.util.*;
    public class Currently {
        public static void main(String[] args) {
            long now = System.currentTimeMillis();
            Date date = new Date(now);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");
            TimeZone tz = TimeZone.getTimeZone("GMT");
            sdf.setTimeZone(tz);
            String output = sdf.format(date);
            System.out.format("%d --> %s%n", now, output);
            long millis = now % 1000;
            now /= 1000;
            long seconds = now % 60;
            now /= 60;
            long minutes = now % 60;
            now /= 60;
            long hours = now % 24;
            System.out.format("Directly from timestamp %02d:%02d:%02d.%03d%n", hours, minutes, seconds, millis);
    }I'm not suggesting one abandon Calendar and DateFormat, but where are the leap seconds since 1970?

  • How can I convert the ITHMB photo files to PC readable format like JPEG?

    How can I convert the ITHMB photo files on my new Iphone 4s to a PC readable format like JPEG

    Look at the link and follow instructions to convert the file taken from a different thread in this forum:
    https://discussions.apple.com/thread/2640386?start=0&tstart=0

  • IPod Classic 160GB film library sync problem -  trying to sync films that have converted from purchased DVD to mp4 format locally, not purchases from the online store - all other libraries sync perfect - why?

    Hello Apple and the iTunes Windows PC users community.
    I am trying to sync films that I have converted from purchased DVD to mp4 format locally, not purchases from the online store. The mp4s all appear and play successfully in my iTunes application but will not sync across to the iPod film library folder.
    For your information: I am using iTunes 11.1.3.8 on a Windows 7 64bit machine with 500GB hard disk and 8GB of Ram in the UK.
    I have restored the iPod classic 160GB three times now to see if it was a hardware problem with no joy. Each time all the music restores properly as do the podcasts and all the items in TV programmes all appear to sync and work fine.
    I have also tried to copy films into the TV Programmes to get around it with no joy. They always go to the films section to start with. It is just the Films library that does not sync - all others work perfectly. As a last resort I have uninstalled and re-installed iTunes with no joy either.
    I am technically savvy and have gone through the itunes and ipod settings but nothing appears to make a difference - This is the first time I have had to post here as I can usually solve the majority of the ipod anomilies but this one has me flummoxed.
    Has the film encoding type changed in the newest itunes update? - Has this happened to anybody else and is it a hardware, software, or operating system problem.

    Having uninstalled the current version 11.1.3.8 and loaded and older version of iTunes 10.7.0.21 I can now categorically confirm that the newest update seems to be causing the problem as the films and TV Programmes are syncing perfectly on this older version.
    If you are going to do this please dont forget to remove the  ' iTunes Library.itl' file as this stops the older versions from running as I've just found out

  • How to convert date from "yyyymmdd" to "MM/DD/YYYY" format

    1. I have one BLDAT field in my internal table.
       its getting updated from input file.
    2. The value in the input file is like yyyymmdd.
       So the internal table field is filled like this
       "YYYYMMDD".
    3. After this,I have to compare this internal table  
       field with BSAD table.
    4. The BLDAT field in BSAD table is in the format of 
       "MM/DD/YYYY".
    5. the BLDAT field is having diff format in internal  table and BSAD table.So I am unable to check this value.
    How to convert it as like the BSAD table format."MM/DD/YYYY" format.
    Thanks in advance!!

    Using the WRITE statement
      data: gd_date(10).  "field to store output date
    * Converts date from 20020901 to 09.01.2002
      write sy-datum to gd_date mm/dd/yyyy.
    OR u can
    CONCATENATE gd_date+4(2) gd_date+6(2) gd_date+0(4)
    into gd_date seperated by '/' .
    Hope this helps.
    Kindly reward points and close the thread for the
    answer which helped u OR get back with queries.

  • Convert amount from flat file format to user format

    hi,
    how to convert amount from flat file format to user specific format.
    input:  1000.00
    output: 1.000,00 (user specific)
    thanks in advance

    move that value to a type WRBTR variable
    and use write statement.
    data v_wrbtr type wrbtr.
    data v_char(20).
    v_wrbtr = 1000.
    write v_wrbtr to v_char.
    v_char will contain the amount in user format.
    Prerequsite, go to SU3 transaction.
    Defaults tab, chose the decimal notation .
    Regards,
    Ravi

  • Converting .prn to a readable format

    Hi,
    I need to capture the .prn files that a certain application creates in a TMP folder and somehow convert it to a readable format like .txt or .doc or .pdf. There are two major problems -
    1. The .prn files get removed from the folder as soon as the print job is over. How do i make them stay??
    2. How to convert the prn file to a readable form such that there are no extra ascii garbage characters.
    3. I tried the windows print dialog box "print to file" option. That doesnt work somehow. It doesnt ask me for any file name. Any ideas about this??
    Can we do something in java to solve this problem.
    Thanks

    I need to capture the .prn files that a certain
    tain application creates in a TMP folder and somehow
    convert it to a readable format like .txt or .doc or
    .pdf. There are two major problems -
    1. The .prn files get removed from the folder as soon
    as the print job is over. How do i make them stay??Ask the people who wrote the application.
    2. How to convert the prn file to a readable form
    such that there are no extra ascii garbage
    characters.Ask the people who wrote the application.
    3. I tried the windows print dialog box "print to
    file" option. That doesnt work somehow. It doesnt ask
    me for any file name. Any ideas about this??Ask the people who wrote the application.
    Can we do something in java to solve this problem.Ask the people...

  • RFC_ERROR_COMMUNICATION: converting to/from net format failed

    dear all,
    when an external program developed in delphi connect to SAP, occurs RFC_ERROR_COMMUNICATION error. but some PC connect SAP successfully through the external program.
    i am puzzled.
    the detail error is below:
    Start ************************************************
    Error Group
    RFC_ERROR_COMMUNICATION
    Message
    Connect to SAP gateway failed
    Connect_PM  GWHOST=192.168.0.252, GWSERV=sapgw00, ASHOST=192.168.0.252, SYSNR=00
    LOCATION    SAP-Gateway on host sapdev / sapgw00
    ERROR       converting to/from net format failed
    TIME        Sun Jul 30 11:30:03 2006
    RELEASE     640
    COMPONENT   SAP-Gateway
    VERSION     2
    RC          734
    MODULE      gwxxrd.c
    LINE        7533
    DETAIL      field = gw_conn_client->lu, rc=512
    COUNTER     2
    End *************************************************
    thank you for your help!

    Dear...
    I have a same problem in our system,and also my computer name is korean.
    Of course If I change my computer name to English, I can solve this problem.
    But is there any other solution to solve this problem except not changing computer name?
    Because our company use active directory and all employer's computer name is korean.
    So maybe changing all computer name is impossilbe.
    So I want another solution.
    Best regards....

Maybe you are looking for

  • How to delete the delta queue in the ECC

    Hi everyone! After I tryed to save a new Infopackage and I have the error : (Deltas already loaded for request REQU_41Q82WJLR9AZCE9ZMKQLVG3RG init. selection; no 2. init Message no. RSM1071 Diagnosis Deltas have already been loaded for the init. sele

  • Moved computers - Error messages - podcasts won't sync - multiple problems

    I just moved my itunes and ipod from a macbook to a PC (I love the apples but I can't afford to buy them). When I plug in my ipod I get two very similar error messages that must be cleared before my ipod will sync (which is very annoying if you're in

  • Creation of PO in SRM without Shopping cart manually.

    I have tried to Create PO in SRM without Shopping cart manually using transaction 'bbp_poc'.But got an error 'the attributes for user cannot be determined, Am I using the correct transaction or not.Do we have any other alternative to accomplish this.

  • Grants running extremely slow

    Hi, We have 10.2.0.3 enterprise oracle instance running on linux and each grant statement is taking about 15 seconds per table ,the logs are clean and memory utilization is good. for running grants of 25K tables its taking 2-3 days. please advise and

  • Track order changed when copying playlist to memory stick!

    Help!! Everytime I try to copy a playlist to a memory stick by highlighting and dragging the track order gets completely jumbled and it's driving me nuts!!! How do I prevent this from happening??!! Thank you for any responses to this question!