Date in miliseconds

hi,
i try to store current date value as integer in my database so i will be able to compare dates by sql command simply like comparing integer values. this is the method i use when i code in PHP. so for this purpose i use Date classes getTime() method to get the time in miliseconds. but i want to ignore hour,minute,second,milisecond values. i need only day,month and year in miliseconds. but how?
also how can i reverse the process to get day,month and year from such milisecond representation?
thaks for your helps...

Try this one :))
import java.util.Calendar;
import java.util.Date;
public class DateConverter {
  Calendar calendar;
     public DateConverter() {
          this( Calendar.getInstance() );
  public DateConverter( Calendar cal ) {
    super();
    calendar = cal;
  public long toMillis( Date d ) {
    long result = -1;
    calendar.clear();
    calendar.setTime( d );
    clearTime();
    result = calendar.getTime().getTime();
    return result;
  private void clearTime() {
    calendar.set( Calendar.HOUR, 0 );
    calendar.set( Calendar.MINUTE, 0 );
    calendar.set( Calendar.SECOND, 0 );
    calendar.set( Calendar.MILLISECOND, 0 );
  public Date toDate( long millis ) {
    Date result;
    result = new Date( millis );
    calendar.clear();
    calendar.setTime( result );
    clearTime();
    result = calendar.getTime();
    return result;
  public static void main(String[] args) {
    DateConverter conv = new DateConverter();
    Date now = new Date();
    System.out.println( "Now is " + now + "\n -> millis " + now.getTime() );
    System.out.println( " -> becomes " + conv.toMillis( now ) );
    System.out.println( " -> as Date " + conv.toDate( conv.toMillis( now ) ) );
    long then = System.currentTimeMillis();
    System.out.println( "Then is " + then + "\n -> Date " + new Date( then ) );
    System.out.println( " -> becomes " + conv.toDate( then ) );
    System.out.println( " -> as millis " + conv.toMillis( conv.toDate( then ) ) );
}Delivers:
Now is Thu Jan 02 12:34:36 GMT+01:00 2003
-> millis 1041507276338
-> becomes 1041505200000
-> as Date Thu Jan 02 12:00:00 GMT+01:00 2003
Then is 1041507276598
-> Date Thu Jan 02 12:34:36 GMT+01:00 2003
-> becomes Thu Jan 02 12:00:00 GMT+01:00 2003
-> as millis 1041505200000

Similar Messages

  • Exist a class for Convert any data to miliseconds?

    Hi!
    I now how to convert current day data to miliseconds, but I don't now how to do it with other data's?
    If it exists what was the format?
    If someone now, could post here the code?
    Thanks

    Hi!
    What you told me was right, but something wrong was happening, look to my results:
    Milis :: 1021735555115
    TIME :: 16:27:34:235
    TIME in MILLISECONDS :: 1019143654235
    And here is the code!!!
    int d = 18;
    int m = 4;
    int y = 2002;
    int hr = 16;
    int mn = 25;
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.set(y,m,d,hr,mn,55);
    long milli = c.getTimeInMillis();
    System.out.println("Milis :: " + milli);
    Calendar now = Calendar.getInstance();
    int hour = now.get(Calendar.HOUR_OF_DAY);
    int min = now.get(Calendar.MINUTE);
    int sec = now.get(Calendar.SECOND);
    int millis = now.get(Calendar.MILLISECOND);
    System.out.println("TIME :: " + hour + ":" + min + ":" + sec + ":" + millis);
    long baseTime = now.getTimeInMillis();
    System.out.println("TIME in MILLISECONDS :: " + baseTime );
    The current hour is 16:28 and what I put in your test is 16:25
    and in milliseconds 16:25>16:28 !
    :( I don' t understand ...
    Thanks
    Andreia

  • Date format with miliseconds

    Hi! I have two columns in a table, TPE_FECHA_SOLICIUTD and TPE_FECHA_EJECUCION (date type). I want subtract the two dates with miliseconds precision.
    The version of database is 9.2.0.4.0
    How can I do it?
    Thanks,

    Not sure about anything.
    15:30:26 SQL> select * from v$version;
    BANNER
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
    PL/SQL Release 8.1.7.4.0 - Production
    CORE 8.1.7.0.0 Production
    TNS for HPUX: Version 8.1.7.4.0 - Production
    NLSRTL Version 3.4.1.0.0 - Production
    5 rows selected.
    15:30:46 SQL> SELECT to_char(sysdate,'dd.mm.yyyy hh24:mi:ss.sssss')
    15:30:50 2 from dual;
    TO_CHAR(SYSDATE,'DD.MM.YY
    28.10.2003 15:31:23.55883
    1 row selected.
    15:30:53 SQL> /
    TO_CHAR(SYSDATE,'DD.MM.YY
    28.10.2003 15:31:23.55883
    1 row selected.
    15:30:53 SQL> /
    TO_CHAR(SYSDATE,'DD.MM.YY
    28.10.2003 15:31:24.55884
    1 row selected.
    15:30:53 SQL> /
    TO_CHAR(SYSDATE,'DD.MM.YY
    28.10.2003 15:31:24.55884
    1 row selected.
    15:30:53 SQL> /
    TO_CHAR(SYSDATE,'DD.MM.YY
    28.10.2003 15:31:36.55896
    1 row selected.
    15:31:06 SQL> /
    TO_CHAR(SYSDATE,'DD.MM.YY
    28.10.2003 15:31:41.55901
    1 row selected.
    15:31:10 SQL>

  • Oracle DATE/TIME COMVERSIONS

    Hi guys!
    This is my second thread about formating a date variable.
    The fact is I would like to increment a date variable in an amount of miliseconds, and after that I want to format the date to this way dd/mm/yyyy 24hh:mmi.
    An example:
    Date Variable Miliseconds to increment Date Resut
    3/13/2007 8:17:28 170000 13/03/2007 08:20
    I also want to convert an amount of miliseconds to a Time Variable (In this case date Variable) to this way 24hh:mi
    An example:
    Miliseconds Time Result
    170000 00:02
    I hope you can help me guys.
    Thanks.

    Miss read
    Milliseconds you can convert to seconds by dividing 1000
    SQL> ed
    Wrote file afiedt.buf
      1  with t as(
      2     SELECT  to_date('12/12/2007 10:00:00','dd-mm-yyyy HH24:MI:SS') LOCALDATE ,3600000 deltat
      3     FROM   dual
      4         UNION all
      5     SELECT  to_date('10/12/2007 5:00:00','dd-mm-yyyy HH24:MI:SS') LOCALDATE ,7200000 deltat
      6      FROM   dual)
      7  select localdate, deltat/(60*60*1000) hours,
      8         to_char(NUMTODSINTERVAL(deltat/1000,'SECOND')+LOCALDATE, 'dd-mm-yyyy HH:MI')
      9* from t
    SQL> /
    LOCALDATE      HOURS TO_CHAR(NUMTODSI
    12-DEC-07          1 12-12-2007 11:00
    10-DEC-07          2 10-12-2007 07:00HTH

  • Advice needed: Efficient way to scan users

    Hi all,
    I wish to know the efficient way to scan users in Lighthouse. I need to write a workflow that checkout all the users and perform some updates. This workflow should run everyday at midnight.
    I have created a scanner myself. Basically what It did are:
    1. call FormUtils.getUsers method to return all users' name into a variable.
    2. loop through this list and call a subprocess workflow to process every user. This subprocess checks out a user view, performs updates, and then checks in view.
    This solution is not efficient at all since it causes my JVM to be Out of Memory. (1G RAM assigned to JVM with about 78,000 users)
    Any advice is highly appreciated. Thank you.
    Steve

    Ok...I know understand what you are doing and why you need this.
    A long, long, long time ago (back in 3.x days) the deferred task scanner was really bad. Its nightly scan would scan ALL users each time. This is fine when your client had 4k users...but not when it has 140k users.
    Additionally, the "set deferred task" function had problems with two tasks with the same name "i.e. disable resource" since it used the name as the xml object name which can not be duplicated.
    soooo, to beat this I rewrote the deferred task handler to allow me to do all of this. Part of this was to add a searchable field called 'nextTaskDate' on the user object. After each workflow this 'date" is updated so it is always correctly populated with the users "next deferred task date"
    each night the scanner runs and querys all users with a nextTaskDate of today. This then gives us a result set that we can iterate over instead of having to list each user and search for tasks. It's a billion times faster.
    Your best bet is to store the task date in miliseconds and make your query a "all users with next task date BEFORE now"...this way if the server is hosed you can execute tasks you may have missed.
    We have an entire re-usable implmentation framework that we have patented (of which this code is a part) that answers most of these types of issues you are bringing up. It makes these implementations much much simpler, faster, scalable and maintainable.
    this make sense?
    Dana Reed
    AegisUSA
    Denver, CO 80211
    [email protected]
    773.412.3782
    "Now hiring best-in-class IdM architects. Inquire via emai"

  • Customer submitted webapp creating blank items

    I have customer submitted webapp - it's part of a custom comments webapp that I've built - the form is part of the detail layout of another webapp and is submitted via ajax - the form has at least one prepopulated field (Name has a value='{module_firstname}' )
    Every thing works as expected 99% of the time - but, I've had a couple of completely blank webapp items end up being submitted?
    If anyone has any thoughts on how/why this could be happening it would be much appreiciated
    I can't supply a link to what I'm taling about as it's all behind a paid secure zone.
    Cheers
    Pat
    I discovered that the problem was that I was using ajax to submit the form and jQuery to add in some additional fields the background. If the user had javascript disabled it would successfully submit the form, even though it had no item name - My solution was to not use the form submit button (which was being prevented from acting as a submit button by jQuery) and attach the 'submit' to a <p> so if javascript is disabled nothing happens (and added a <noscript> message so the user would know what was going on.

    Hey Pat,
    Regarding the first question - I am afraid the only way to set the expiry date is to add X days to the current date, so calculating the number of days between the date you want the item to expire and the current days is the way to go here.
    Regarding the second question I am afraid there is no "easy" way around this, weight values cannot be assigned through the front-end, so sorting is limited to the default options (date, datereverse, alphabetically and so on). One way I'd see this happening is like so
    -define a layout that renders all the webapps
    -using js convert the event date to miliseconds and hide the events you do not want to show
    There are some potential performance issues with this approach, if you need to display alot of items (with pictures for example) the system will load all the items every time and then hide the ones that are outside the desired range.
    A more complicated way of rendering specific webapp items would be to create a "lightweight" list layout containing only the URL and the event date field (this should load up fairly fast) and then using ajax load only the needed items into the page. I would advise to use this approach in case you run into performance issues caused by loading the "detail" layout of the webapps.
    Hope this helps,
    Mihai.

  • 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".

  • Timestamp Datatype

    Hi Gurus,
    I have column (datatype-timestamp) in physical layer but as when i am checking in user interface found only date is displaying
    Any clue regarding to this
    thanks

    Hi Gurus,
    I viewd the data in the physical layer it shows in date,time,miliseconds
    datatype is also timestamp.when i am casting it shows the data but without casting onlyn dates are coming
    it shows some gap(blanck space) after the date
    thanks
    Edited by: user1124854 on Nov 10, 2010 6:33 AM

  • Date format in miliseconds

    Do you know if we can use the date format in miliseconds with TO_CHAR() function?

    Not if you are using a DATE data type. DATE columns do not store sub-second precision. You would have to be using a TIMESTAMP data type to see milliseconds.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • WCF Data services remove miliseconds from DateTime when expand

    I get some strange behavior, when using WCF Data Services 5.6. In my case, I have table, with 1 column set with Concurrency=Fixed, and this column hold date time field from database, updated each time when row is edited. In case I just retrieve entity -
    this column has correct value with milliseconds. But if I do mapping - milliseconds are removed.
    Here is a issue at glance :
    ====================================================================
    void Main()
    var b = from p in TABLE1 where p.ID == 100 select p;
    b.Dump();
    Request in this case is : Data.svc/TABLE1(100M) And data returned from service is :
    <d:COL1 m:type="Edm.DateTime">2015-02-16T12:13:52.972</d:COL1>
    ====================================================================
    As you can see , here time is returned with milliseconds - .972 In other case :
    void Main()
    var tmp = from p in TABLE1 where p.ID == 100 select
    new TABLE1()
    ID=p.ID,
    COL1=p.COL1
    var a1 = tmp.ToList();
    a1.Dump();
    Request in this case is : Data.svc/TABLE1(100M)?$select=ID,COL1
    <d:COL1 m:type="Edm.DateTime">2015-02-16T12:13:52</d:COL1>
    ====================================================================
    Time is returned without milliseconds.
    Does anybody have same problem? May be its a bug in the WCF Data services or in the model?

    Ok, seems like I found an answer to this, or at least way to avoid the problem.
    First I traced generated SQL from framework, and I see that in first case, im getting SQL
         SELECT ID, COL1 FROM TABLE1
    and in second case, I got
         SELECT ID, CAST( COL1 AS DATETIME) FROM TABLE1
    which cause the problem.
    Then I tried to update EF to version 6, WCF Data services to version 5.6.3,
    Oracle ODP to latest one, tried to use Oracle managed driver... no any success.
    Then I played little bit with table definition, and I saw that my col1 with type TIMESTAMP in database and DateTime in the model was defined as NOT NULL.
    If I remove this from database definition, I got right value with milliseconds.
    So , may be this is a bug in Oracle driver, but probably this is a bug in the WCF Data Services. At least I found a way to use concurrency in my case with this solution.

  • I need to see Date Created Order to the second, not minute.

    I currently shoot sport on two camera bodies, Nikon D3 and D3s.  The timing of the shots is critical and I need to sort them in "Date Created Order" in Adobe Bridge. The software usually does a very good job of this, it seems to know, which order to arrange them in, but sometimes I need to rearrange the order manually.  To do this I need to be able to see, to the second, when each file was created.  In Adobe Bridge, I only seem to be able to see which minute the file was created.
    Windows 7 Adobe Creative Cloud and CS6
    Many thanks,
    Matt

    Maybe you are not looking at the correct place to see the seconds, but indeed, it would have been more easier if you could select the seconds also to show under the thumbs, would make a great Feature Request.
    I include some screenshots from my (customized) workspaces, your's might vary but the goal is the same.
    Here is a part of my usual workspace showing content, preview and metadata panel. In the metadata panel you will find what you are looking for (at least in seconds instead of minutes):
    And from the default metadata workspace (should be possible to customize much more but it isn't and therefor almost useless for my workflow):
    Problem when needing the milisecond info I don't know a way in panels other then maybe using scripting or third party exif change applications. But If you need to look for it it usually can be find in the file info intself under the Raw Data tab (this is for a Canon CR2 file, YMMV:
    Hope this helps a bit.

  • SQLDatabase: Read a lot of data at once and process in memory or read the data when I need it?

    I'm not sure how to approach this problem. I require a big chunk of data records from the SQL server. This chunk is based on variables, so I don't know before what records I need. I need to do a large series of calculations and each calculation requires one
    (or more) records from this chunk of data. Again: I do not know which records are required.
    Should I:
    A. Load this data into the application memory all at once
    This creates a single connection to the DB, loads ALL required data by a query command (and a forward only DataReader) and then doesn't bother the SQL server anymore.
    The datafetch seems to be slow, since it's reading hundred of thousands of lines into memory
    B. Whenever the calculation needs data, retrieve it from the database
    This would open and close a connection to the SQL db multiple times per second.
    The initial datafetch is reduced to only a few miliseconds, but creates a massive load on the SQL server during calculation.

    Firstly, if you can turn your whole calculation in to an SQL query (or a series of queries or a stored procedure) then do so. Databases are good at this stuff, and you or a DBA may be able to do a lot to improve the query if it's still too slow.
    If not:
    Use a connection pool. Not doing so is usually crazy, unless you're writing a script that only connects once or twice.
    If you're testing this in a development environment with a local DB, beware that there can be a big difference in performance characteristics compared to a production one and don't over-optimize based on what you measure. Network delays in particular could
    catch you out. Fetching one row at a time may be fine with a low network latency, and awful with a high one.
    Database sizes are usually bigger in production, and go up over time. If you fetch all the data in advance you could get caught out and run out of memory (unless you know more about your data then we do...).
    As Pieter B suggests, you're probably better fetching data in batches if you really need a large number of rows. Then you'll neither blow everything else out of your server's memory, nor have a network latency and query overhead on every row. It'll also help
    if you want to report progress to the user.
    If you're really serious about making it go as fast as possible and not using SQL to do it, then you could try parallelizing your code. Then you can be calculating with
    one set of data whilst fetching the next, and if your production DB has multiple cores and disks you can parallelize in the DB, too. You could also look at caching, if that's appropriate (memcached and similar, or directly in your server if you know your data
    sizes well enough).

  • Convert time in miliiseconds to date format

    I have a column in my table with datatype number(38,0) , in that column i have values in form of miliseconds since 1970 e.g 1152567973042...
    i have a requirement to convert this time in milliseconds to today's date, which i can do as
    1152567973042 / 3600 / 24 / 365 == x
    1970 + x = today's date
    is there a function in oracle supporting this, or i have to customize my requirements and write a function.
    Thanks in anticipation

    Your function will not work precisely because it does not account for leap years. You should use Oracle date math. If you add a number to an Oracle date datatype, it assumes that the number is in days. Oracle will automatically account for leap years. Try this:
    DECLARE
    mydate DATE;
    milliseconds_since_1970 NUMBER(30,7);
    BEGIN
    milliseconds_since_1970 := ?;
    mydate := TO_DATE( '01-JAN-1970', 'DD-MON-YYYY') + milliseconds_since_1970/(1000*60*60*24);
    DBMS_OUTPUT.PUT_LINE('mydate = ' || to_char( mydate, 'DD-MON-YYYY HH24:MI:SS' ) );
    END;
    This converts your milliseconds (replace ? with the number) to days and then adds the days to January 1, 1970. The result is an Oracle date datatype adjusted for leap years.
    Oracle date datatypes have hours, minutes, and seconds. Since these were not specified for 1/1/1970, they default to zero. Since milliseconds_since_1970 has 7 decimal places, it will contain fractional days which Oracle converts to hours, minutes, and seconds.
    I'm not sure what format Oracle stores date datatypes in. You have to convert them with a format string every time you use them.
    Kevin Tyson

  • Date problems

    Guys,
    I'm getting problem with a date conversion. I don't know what's wrong, but I know that it's wrong....
    Could somebody confirm this date for me ???
    #3d2d2d2d
    dateformat = (dd/mm/yyyy hh:mm:ss.mmm am/pm)
    I'm getting 11/06/2002 04:01:01.000 am, but I should get 05/12/2002 04:01:01....
    Any help is very welcome,
    thanks
    /jcf - follow I'm sending the code that I made the conversion...
    import java.util.*;
    public class DataConv {
    public DataConv() {
    public void start() {
    String xx = new String("#3d2d2d2d");
    System.out.println("-> " + xx);
    System.out.println("-> " + Long.decode(xx));
    Date d = new Date(Long.parseLong(Long.decode(xx).toString() + "000"));
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(d);
    System.out.println("DIA = " + gc.get(gc.DAY_OF_MONTH));
    System.out.println("MES = " + gc.get(gc.MONTH ));
    System.out.println("ANO = " + gc.get(gc.YEAR ));
    System.out.println("HORA = " + gc.get(gc.HOUR_OF_DAY ));
    System.out.println("MINUTO = " + gc.get(gc.MINUTE ));
    System.out.println("SEGUNDO = " + gc.get(gc.SECOND ));
    System.out.println("MILISECOND = " + gc.get(gc.MILLISECOND ));
    public static void main(String[] args) {
    DataConv dataConv1 = new DataConv();
    dataConv1.start();
    }

    I'm not convinced this should even run, let alone run correctly.
    For the date string you give, I get the day 11 June 2002 as well, both in java and using perl (using seconds instead of milliseconds). Are you sure that value should be 5 Dec 02?
    Secondly, Date's constructor with a String is deprecated.
    Third, apparently Date's String constructor doesn't like the string to hold milliseconds since epoch.
    Fourth, why are you turning things into strings and back again and into strings and back again?

  • Data Writing Speed for Excel Sheet while taking data from PCI DAQ card

    Dear All,
              I am taking the data form the card EX-92026 pci card and writing those datas into the Excel sheet, now i want the data at the speed of max of 10 miliseconds but while writing the data into excel sheet, it shows the diff of 15 ms betn 2 readings, and the card specs says it takes the time of 500 microsecs to give the data, so is there any effect of timing, while writing data into excel sheet? is labview take more time, i am using the Open file, write file and close file method and write to spreadsheet file method, but none of them is giving me the effective timing that i wamt, so can u tell me how can i reduce it??????
    Thanks,
    Nishant

    Hi Nishant:
    I think I don't understand you very well. If you are using OpenFile, CloseFile and WriteToSpreadsheet VIs, you are not dealing with excel files, but text files.
    Writing to file is costly in time. You can:
    Open the file just once and
    during de process use just file writing VIs as 'write to spreadsheet'... or a more simple one 'write file'
    Close the file once at the end.
    If you need the process to be faster, you can save all the data at 10ms rate in an array and write to file at the end.
    Or write to file every second what you got the last second.
    Hope it helps
    Aitortxo.
    Aitortxo.

Maybe you are looking for

  • Mouse clicks blocked improperly when stage resizes

    Hi everyone, Been working on this for a while with no success. would really appreciate your help. We have the following issue: 1 main flex application is loading another flex application swf using a swfloader placing the child app in the same securit

  • How do I get thius crap off of my computer

    How do I get this crap off of my computer, I used uninstall, but the folder and other things will not delete, putting something on my computer that I can not remove is a federal offence, tell me how to get this OFF, and I won't make any phone calls.

  • Disc Utility for Parallels Prep and Memory Issue

    I'm having no luck with starting threads on the Parallel's forum so here I go: A question about configuring. I'm going to be installing Parallels 3.0 and have a Power Pro with two 500 GB internal drives. My Mac Apps and OSX are on one drive with the

  • Griffith "by collection" feature doesn't work

    Hi All, I'm using griffith to catalog my video collection and I have three collection categories, children, music and films. When I click on "by collection" and select one of the categories there is no change in the list. I have opened the same backu

  • How do I eliminate uneven edges in fill color?

    Hello Adobe Community! I have created a color gradient and the color fill has an uneven edge, which creates a small white space between the edges of the fill and the bounding box.  I have tried using shift+click to try and even the edges, but I guess