Problem to convert milliseconds to date

Hello:

I have a long type with milliseconds which have information from an external source. This information is GMT + 1 dates from the period. The problem is that if I convert it to a Date of (Date d = new Date (xmilliseconds)), the result is different in Simulator and real device. I have in this time zone GMT + 1 devices. What can I do to resolve this difference?

Thank you.

The java.util.Date object is simply a wrapper for a value of type long, counting the milliseconds from the time (midnight UTC 1970-01-01).

long millis = 1240849164046l;
java.util.Date date = new java.util.Date(millis);
boolean alwaysTrue = (millis == date.getTime()); // regardless of phone's timezone

SimpleDateFormat, however, depends on the phone zone.

long tzOffset = TimeZone.getDefault().getRawOffset();
System.out.println("Default Timezone offset: " + tzOffset);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
System.out.println("Epoch: " + sdf.format(new Date(0l)));
long now = System.currentTimeMillis();
System.out.println("Now: " + sdf.format(new Date(now)) + " (millis = " + now + ")");

In Chicago outputs:
Default Timezone offset: -21600000
Epoch: 1969-12-31 18:00:00 America/Chicago
Now: 2009-04-27 11:20:15 America/Chicago (millis = 1240849215406)

In Tokyo (at just about the same moment) outputs:
Default Timezone offset: 32400000
Epoch: 1970-01-01 09:00:00 Asia/Tokyo
Now: 2009-04-28 01:19:24 Asia/Tokyo (millis = 1240849164046)

Note that 0 millis formats 'evil' (not midnight) in both cases. It is not a bug, it's how it is supposed to work.

System.currentTimeMillis () returns the milliseconds from the time (no matter what time of the phone). If everyone called him at the same time, we would have to pretty much the same result (small variations for the clocks that are a little faster or a little slow).

If everyone calls new (Date()) sdf.format at the same time, we would each get local time. That's what we want to achieve. That's why SimpleDateFormat compensates millis since the time for the local time zone before formatting.

If you want SimpleDateFormat to show the millis count as-is, you need to compensate with the local time zone as follows:

sdf.format(new Date(millis - TimeZone.getDefault().getRawOffset()))

This will return the same string regardless of the phone's time zone. With millis = 0 This reformatted as midnight 1970-01-01, new, independently of the phone's time zone.

As the external source is GMT + 1, the returned string will be off by one hour. It may be a good idea to move the source external to UTC when you import it. This way you can do the math as (System.currentTimeMillis () - externalTime) and get the correct answers.

Cheers, Barak.

p.s. The GMT and UTC are not the same thing. They are a few seconds apart, which makes no difference for non-scientific applications.

Tags: BlackBerry Developers

Similar Questions

  • How to convert to format Date in milliseconds

    Hi all

    I am getting the output of a variable in milliseconds format, how can I convert it in date format

    For ex: I get variable input like 1366664691000 and I need to convert it to April 22, 2013 23:04:51 CEST (or SOA form). is there any function for this in XSL or XPath?

    Thank you

    Hello

    My XSLT works now after making a few changes

    and included namespace xmlns:fn = "http://www.w3.org/2005/xpath-functions.

    Now, I'm successfully number of days. My use case is to delete the files of the bases on the number of days. (i.e. changed the time - current date).

    Once again thank you @ vladidos

  • Convert number to date format

    HI team,

    I have a problem, how we can convert number in date format?
    This is the result of the query.

    SQL > col START_TIME for 999999999999999999999999
    SQL > select start_time in qrtz_triggers;

    START_TIME
    -------------------------
    1364243906000
    1364589406000

    So, I have to change the date format niumber rto.

    My date format as for example: "" Mar 25,2013 20:36:45 ""


    Please suggest me...
    Thank you
    Chavigny

    Published by: 939938 on March 14, 2013 06:39

    This is the number of milliseconds since January 1, 1970.

    SQL> SELECT to_char(to_date('01/01/1970','mm/dd/yyyy')+1364243906000/24/60/60/1000
      2  ,'Mon dd, yyyy hh:mi:ss PM') FROM dual;
    
    TO_CHAR(TO_DATE('01/01/1970','
    ------------------------------
    Mar 25, 2013 08:38:26 PM
    

    So in your query instead of start_time use
    TO_CHAR (to_date (' 01/01/1970 ',' mm/DD/yyyy') + start_time/24/60/60/1000,' Mon DD, YYYY HH: mi: ss PM "")

    Published by: kendenny on March 14, 2013 08:31
    Had used mm instead of e for the minutes.

  • problem with the type of date dd/mm/yyyy

    Hi all!
    I want to do something simple.
    to get a type of dd/mm/yyyy string and convert it ti date jj/mm/aaaa type.
    I wrote simple code
    String pattern = "dd/MM/yyyy";
    SimpleDateFormat format = new SimpleDateFormat (pattern);
    try {}
    Date = format.parse("12/03/2006");
    System.out.println (date);
    } catch (ParseException exception) e {}
    e.printStackTrace ();
    }

    but the problem that I get Sun Mar 12 00:00:00 GMT + 02:00 2006
    and I want to get this format dd/mm/yyyy.
    because I need to insert it in my db. Thank you all

    First thing: almost always if a SQL statement uses variable data, use a PreparedStatement. With the help of a simple statement can, at first, most obvious glance, but it will cause endless problems.

    The constant strings in SQL are "single quotes" i.e. apostrophes. They must at least cannot escape string constants. One of the reasons for always using class PreparedStatement is that you concatenate in a string value may contain an apostrophe. In this case it will be, at best, give your SQL syntax error. Worse it can make your system vulnerable to hackers.

    Use code publishing code tags. Put the word 'code' braces before and after. This makes your code readable.

    The field attribute by DEFAULT when you create a table must be a real date, not a model. I have never know this is useful for a date, except if it set to pick up the current date.

  • Convert Varchar to Date of the

    Hello


    Im trying to convert varchar to date.

    So I used To_date (cilumn, 'DD-MM-YYYY'), since I have to order the set in descending order, I used the same function of conversion with order by clause.


    The problem is... put it is not ordered.


    < sql >

    Select date_created
    Of
    (
    Select distinct
    to_date(created_date,'DD-mm-YYYY') as date_created
    of schedule_backup
    )
    order by desc date_created
    /

    < sql >




    out put is
    =================




    DATE_CREA
    ---------
    26 NOVEMBER 09
    23 NOVEMBER 09
    19 NOVEMBER 09
    16 NOVEMBER 09
    11 NOVEMBER 09
    4 NOVEMBER 09
    30 OCTOBER 09
    11-SEP-09
    4 MARCH 10
    MARCH 1, 10
    FEBRUARY 25, 10

    DATE_CREA
    ---------
    FEBRUARY 22, 10
    17 FEBRUARY 10
    FEBRUARY 15, 10
    11 FEBRUARY 10
    FEBRUARY 9, 10
    FEBRUARY 3, 10
    27 JANUARY 10
    20 JANUARY 10
    JANUARY 15, 10
    JANUARY 4, 10




    Thank you
    REDA

    So it's a problem with the data itself

    Check below

    SQL>SELECT TO_CHAR(a,'DD-MON-YYYY')
      2        ,TO_CHAR(b,'DD-MON-YYYY')
      3    FROM (
      4          SELECT TO_DATE('03-FEB-10','DD-MON-YYYY')    a
      5                ,TO_DATE('03-FEB-2010','DD-MON-YYYY')  b
      6            FROM DUAL
      7         ); 
    
    TO_CHAR(A,' TO_CHAR(B,'
    ----------- -----------
    03-FEB-0010 03-FEB-2010
    
    Elapsed: 00:00:00.04
    SQL>
    

    Data are not in a consistent format DD-MON-YYYY or DD-MON-AA. It is a format of mix that impact of output as shown above

    Concerning
    Arun

  • Convert a varchar2 data type Date

    Hi guys,.

    Can someone help me convert a Varchar2 data type in the data type Date?

    I have a query and my column is a varchar2 data type.
    I want to just that convert the Varchar2 in a DATE, because I met
    problem in my query. I want to do the day1 day10 transaction.

    Ex:
    Day 1 = January 1, 2010
    Day10 = January 10, 2010

    table.record_date varchar2 (12)

    SELECT column1, Column2
    table
    where record_date between? and?

    How can I set the record_date between day1 and day10 since record_date is of type varchar?

    Thank you.

    Laetitia

    Lala,

    If the data in the database are in the format MM-DD-RR , then you must use the same format when you convert back to this day.

    So change the query to

    SELECT COLUMN1, COLUMN2 FROM TABLE WHERE TO_DATE(RECORD_DATE, 'MM-DD-RR') BETWEEN TO_DATE('01-JAN-2010') AND TO_DATE('10-JAN-2010')
    

    Kind regards

    Manu.

  • Problem running windows 10 to date for windows 7 Home premium 64-bit reference error code 08C 1800103 - 089002

    Problem running windows 10 to date for windows 7 Home premium 64-bit reference error code 08C 1800103 - 089002

    Could not update windows 7 Home premium service pack 1 for windows 10.

    I tried windows update. all updates are installed except win 10 update that comes up with unexpected error

    Please be aware, even if you do not get the Windows 10 app, you can always download Windows 10 as one. ISO file, create a bootable copy and update your system.

    See the instructions: How to download official Windows 10 ISO files

    Task of pre-required

    When you make significant changes to your computer for example updated operating system, you must always back up. See the links to resources on the backup by clicking the link for each version of Windows you are using: Windows XP, Windows Vista, Windows 7, Windows 8/8.1

  • Convert char to date format in obiee 11g?

    Hello

    I want to convert char to date format in obiee 11g.

    I have this date

    ' 07/31 /' | CAST (YEAR (CURRENT_DATE) AS CHAR)

    I want to change the tank to the date format.

    Please help me,

    Thanks in advance,

    A.Kavya.

    Below him is based on my date format NLS source Oracle database as DD-MON-RR (query on the database - SELECT * > OF nls_database_parameters WHERE the PARAMETER = "NLS_DATE_FORMAT").

    Note that this is not altered by the connection of the RPD pool, which is common.

    If the date that I put together for substrings and Casts a match before it can be LAUNCHED as a DATE. IE 31 July 15 etc.

    Steps to follow:

    -Drag a field to the report, one

    -Change the formula

    -Paste in

    CAST ("31 - Jul -" |) SUBSTRING (CAST ('F_PL_BAL'. ' BUSINESS_DATE ' AS CHAR) FROM 8 TO 2) AS DATE).

    -OK

    -See the results

  • Convert milliseconds of time in dateTime in XQUERY

    Hi all

    I have a requirement to convert milliseconds of time in dateTime in XQUERY OSB. Can you help me please?

    Ex: 1445495501169

    Concerning

    Hi Aditya,

    You can try the code in the snippet below.

    declare function xf:test ($epoch as XS: long)

    as XS: DateTime {}

    XS:DateTime("1970-01-01T00:00:00") + ($epoch * xdt:dayTimeDuration('PT0.001S')))

    };

    It will be useful.

  • Import excel should allow space in a column during the use of media: the value class coldfusion.sql.QueryColumn can not be converted to a date

    I followed the pretty good learncfinaweek and can see no error in my code.   Here is the error, that should solve and the page with the code.  Any help is appreciated.  This should be quite simply like this: < cfset blogPost.dateposted = importData ["posted Date"] / >, which allows the column in excel with a space between words.

    Good: dateposted - the coldfusion.sql.QueryColumn class value cannot be converted to a date.

    Root cause: org.hibernate.HibernateException: property: dateposted - the coldfusion.sql.QueryColumn class value cannot be converted to a date



    "< cfimport taglib ="... /... "/ customTags" prefix = "ct" / >

    < ct:securityCheck redirectPage = "#cgi.script_name #" / >

    < name = "cfparam form.submitted" default = "0" / > "

    "< name =" cfparam form.importFile"default =" "/ >

    < cfif form.submitted >

    <! - Download file - >

    < cffile action = "upload" destination = "#getTempDirectory ()" # "filefield ="importFile"nameconflict ="makeunique"/ >"

    <!--> reading spreadsheet

    "< cfspreadsheet action = 'read' src="#cffile.serverDirectory#/#cffile.serverfile# ' query = headerrow "importData" = "1" excludeheaderrow = "true" / >

    <!--> Import data

    < cfloop query = "importData" >

    < cfset blogPost = entityNew ('blogPost') / >

    < cfset blogPost.title = importData.title / >

    < cfset blogPost.summary = importData.summary / >

    < cfset blogPost.body = importData.body / >

    < cfset blogPost.dateposted = importData ["posted Date"] / >

    < cfset EntitySave (blogPost) / >

    < / cfloop >

    < cfset ormFlush() / >

    < cflocation url = "listblogpost.cfm? message = #urlencodedformat ('Blog Posts Imported Successfully')" # "addtoken ="false"/ >"

    < / cfif >

    < cfoutput >

    < section ct:layout = "Summary" >

    < section = 'blog' active 'post' = ct:navigation / >

    < div class = "span10" >

    The Blog posts to download < h2 > < / h2 >

    < form class = "form-horizontal" action = "" #cgi.script_name # "method ="post"enctype =" multipart/form-data">"

    < div class = "control group" >

    < class label = 'label control' for 'importFile' = > import file < / label >

    < div class = "orders" >

    < input type = "file" id = "importFile" name = "importFile" value = "#form.importFile #" >

    < / div >

    < / div >

    < div class = "control group" >

    < div class = "orders" >

    < button type = 'submit' class = "btn, btn-primary" > download < / button >

    < / div >

    < / div >

    < input type = "hidden" name = "subject" value = "1" / >

    < / make >

    < / div >

    < / ct:layout >

    < / cfoutput >


    DavidSCarlisle55 wrote:

    I changed the date to 'YYYY-MM-DD' in the xls file by changing to the UK format within excel.

    It is still giving an error.  ?

    Odd. Then there can be only one solution to the riddle: what you read is a column name, and not the date value stored in the column.

    See what happens when you replace this line by

    or, perhaps better,.

  • Dynamics Processor Calc does not reach more than [100] ESM blocks during the calculation, please increase the CalcLockBlock setting, and then try again (a small data cache setting can also cause this problem, check the size of data cache setting).

    Hello

    Our environment is Essbase 11.1.2.2 and work on Essbase EAS and components of Shared Services. One of our user tried to execute the Script of Cal of a single application and in the face of this error.

    Dynamics Processor Calc does not reach more than [100] ESM blocks during the calculation, please increase the CalcLockBlock setting, and then try again (a small data cache setting can also cause this problem, check the size of data cache setting).


    I did a few Google and found that we need to add something in the Essbase.cfg file as below.

    Dynamics Processor Calc 1012704 fails to more blocks ESM number for the calculation, please increase the CalcLockBlock setting, and then try again (a small data cache setting can also cause this problem, check the size of data cache setting).

    Possible problems

    Analytical services cannot lock enough blocks to perform the calculation.

    Possible solutions

    Increase the number of blocks of analytical Services can allocate to a calculation:

    1. Set the maximum number of blocks of analytical Services can allocate at least 500.
      1. If you are not a $ARBORPATH/bin/essbase.cfg on the file server computer, create one using a text editor.
      2. In the essbase.cfg folder on the server computer, set CALCLOCKBLOCKHIGH to 500.
      3. Stopping and restarting Analysis server.
    2. Add the command SET LOCKBLOCK STUDENT at the beginning of the calculation script.
    3. Set the cache of data large enough to hold all the blocks specified in the CALCLOCKBLOCKHIGH parameter.

    In fact in our queue (essbase.cfg) Config Server we have given below added.

    CalcLockBlockHigh 2000

    CalcLockBlockDefault 200

    CalcLockBlocklow 50


    So my question is if edit us the file Essbase.cfg and add the above settings restart services will work?  and if yes, why should change us the configuration file of server if the problem concerns a Cal Script application. Please guide me how to do this.


    Kind regards

    Naveen

    Yes it must *.

    Make sure that you have "migrated settings cache of database as well. If the cache is too small, you will have similar problems.

  • How to convert a hex date?

    I notice with the release of SharePoint Foundation 2010 metadata using cfsharepoint dates/times are converted in the following format: 0x01cf2d81. 0x71c80a00

    How to convert it to a regular date using ColdFusion?  I found a few references to this question here http://sharepoint.stackexchange.com/questions/66602/dates-and-times-in-properties-vs-field s/91069 #91069 which shows a solution like this:

    //fieldValue looks like "0x01cf2f8e|0x6e559e00"
    string fieldValue = listItem.Properties[dateFieldName]
    string hexValue = fieldValue.Replace("|", "").Replace("0x", "");
    long ticks = long.Parse(hexvalue, NumberStyles.HexNumber);
    
    DateTime date1 = DateTime.FromBinary(ticks).AddYears(1600);
    

    But I have no idea how to do that in ColdFusion.  Apparently, the hexadecimal value represents the number of ticks since January 1, 1600.  Crazy, I know.

    Any ideas?  Thank you.

    Thanks for your help in this, Alexander.  I have worked on this for a day and discovered some useful information and finally found an easier way to do this.

    Below, you will see that the number of ticks can actually be retrieved using the method of parseLong() of Java.  I don't know what is happening with inputBaseN or why it does not work for this scenario, but we cannot forget that for now.  Also, I discovered Windows time system does not start at 1600, he begins to 1601.  The guy in the article I linked to really wrong, so apologies for any confusion on that!  Finally, I convert the date in local time.

    Here's the complete code to convert the hexagonal date of SharePoint at regular date using ColdFusion.  Hope this helps someone in a similar situation.

      
      
      
      
      
      
      
      
      
    

    By the way, here's a cool article about a guy who goes to something similar: http://ruthsarian.wordpress.com/category/programming/coldfusion/

  • I want to convert the double data type to string type

    I want to convert the double data type to string, have idea about that

    Hello

    Use f

    FN: String (ARG) returns the string value of the argument. The argument can be a number, boolean, or node-set element

    Example: string (314)
    Result: "314".

    http://w3schools.com/XPath/xpath_functions.asp#string

    See you soon,.
    Vlad

  • Problem link DB between active Data Guard and reports application database

    My version of the 11.2.0.2.0 and OS database is Oracle Solaris 10 9/10.
    I am facing a problem in my custody of data Active data base for purposes of tax. Active Data guard information is as below.

    SQL > select name, database_role, open_mode from v$ database;

    NAME DATABASE_ROLE OPEN_MODE
    --------- ---------------- --------------------
    ORCL PHYSICS READ SHALL ONLY APPLY

    Detail of the problem is less than
    ------------------------------
    I have created a db link (name: DATADB_LINK) between active data guard and report of application of data base for purposes of tax.
    SQL > create database DATADB_LINK link to connect to HR identified by HR using 'DRFUNPD ';
    Database link created.

    But when I run a query using db link to my database of enforcement report I got this error below.

    ORA-01555: snapshot too old: rollback segment number 10 with the name ' _SYSSMU10_4261549777$ ' too small
    ORA-02063: preceding the line of DATADB_LINK

    Then I see logfile named database alart Active Data Guard and get below error

    ORA-01555 caused by the following SQL statement (SQL ID: 11yj3pucjguc8, time of request = 1 sec, SNA: 0x0000.07c708c3): SELECT "A2". "' BUSINESS_TRANSACTION_REFERENCE ', 'A2 '. "' BUSINESS_TRANSACTION_CODE ', MAX (CASE 'A1'. "TRANS_DATA_KEY"WHEN "feature' AND 'A1'." " END OF TRANS_DATA_VALUE"), MAX (CASE 'A1'. "TRANS_DATA_KEY" WHEN 'otherFeature' THEN 'A1' '. "" END OF TRANS_DATA_VALUE")

    But the interesting point if I run the query report directly in the Active Data Guard database, I got never error.

    So it's a problem of link DB between active Data Guard and other databases?

    Fazlul Kabir Mahfuz wrote:
    My version of the 11.2.0.2.0 and OS database is Oracle Solaris 10 9/10.
    I am facing a problem in my custody of data Active data base for purposes of tax. Active Data guard information is as below.

    SQL > select name, database_role, open_mode from v$ database;

    NAME DATABASE_ROLE OPEN_MODE
    --------- ---------------- --------------------
    ORCL PHYSICS READ SHALL ONLY APPLY

    Detail of the problem is less than
    ------------------------------
    I have created a db link (name: DATADB_LINK) between active data guard and report of application of data base for purposes of tax.
    SQL > create database DATADB_LINK link to connect to HR identified by HR using 'DRFUNPD ';
    Database link created.

    But when I run a query using db link to my database of enforcement report I got this error below.

    ORA-01555: snapshot too old: rollback segment number 10 with the name ' _SYSSMU10_4261549777$ ' too small
    ORA-02063: preceding the line of DATADB_LINK

    Then I see logfile named database alart Active Data Guard and get below error

    ORA-01555 caused by the following SQL statement (SQL ID: 11yj3pucjguc8, time of request = 1 sec, SNA: 0x0000.07c708c3): SELECT "A2". "' BUSINESS_TRANSACTION_REFERENCE ', 'A2 '. "' BUSINESS_TRANSACTION_CODE ', MAX (CASE 'A1'. "TRANS_DATA_KEY"WHEN "feature' AND 'A1'." " END OF TRANS_DATA_VALUE"), MAX (CASE 'A1'. "TRANS_DATA_KEY" WHEN 'otherFeature' THEN 'A1' '. "" END OF TRANS_DATA_VALUE")

    But the interesting point if I run the query report directly in the Active Data Guard database, I got never error.

    So it's a problem of link DB between active Data Guard and other databases?

    Check this statement that applies to your environment

    * ORA-01555 on Active Data Guard Standby Database [1273808.1 ID] *.

    also

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:8908307196113

  • convert the varchar2 data type to the data number type

    How to convert the varchar2 data type to the data type number.


    It looks like my data

    create table one)
    col1 varchar2 (50)
    col2 varchar2 (500);

    Insert in a (col1, col2) values ('1234 ', ' 2345');

    Select Column1 of number (19)) cast (to_number (col1);

    IAM getting error invalid number


    I need to create a table with the same columns with data like number types (19)

    can someone help me

    Thank you

    You have changed your original post, so now I see that you get the invalid number.

    This is why you should always avoid the varchar columns to store numbers or dates...

    Since your table source contains a nonnumeric value, you can write a pl/sql to convert data and see what records are false:

    SQL> insert into a (col1,col2) values ('xxxx','2345');
    
    1 row created.
    
    SQL> select * from a;
    
    COL1     COL2
    -------- --------
    1234     2345
    xxxx     2345
    
    2 rows selected.
    
    SQL> create table b (col1 number(19), col2 number(19));
    
    Table created.
    
    SQL> set serverout on
    
    SQL> declare
      2  cursor c is
      3  select * from a;
      4  begin
      5    for r in c loop
      6     begin
      7       insert into b values (to_number(r.col1), to_number(r.col2));
      8     exception
      9       when invalid_number then
     10        dbms_output.put_line('Row rejected: col1='||r.col1||' col2='||r.col2);
     11     end;
     12    end loop;
     13  end;
     14  /
    Row rejected: col1=xxxx col2=2345
    
    PL/SQL procedure successfully completed.
    
    SQL> select * from b;
    
          COL1       COL2
    ---------- ----------
          1234       2345
    
    1 row selected.
    

    Max

    Published by: Massimo Ruocchio, June 14, 2011 20:00
    Added the first query in the example

Maybe you are looking for