Fetch Epoch time

Hi: I want to build a small java code that returns the unix epoch time for 12:00AM yesterday and 11:59PM yesterday. Anybody have code which does the above that you can share ?
TIA
Ravi

This should do what you're looking for:
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Main {
  public Main() {
  public static void main(String[] args) {
    final long MS_PER_DAY = 24 * 60 * 60 * 1000;
    // Get the current time
    Date now = new Date();
    // Get a time from yesterday
    Date yesterday = new Date(now.getTime() - MS_PER_DAY);
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(yesterday);
    // Get the time yesterday morning at 12:00AM
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date yesterdayStart = calendar.getTime();
    // Get the time yesterday night at 11:59:59PM
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date yesterdayEnd = calendar.getTime();
    System.out.println(
      "Yesterday start: " + yesterdayStart +
      "\t Since Epoch:" + yesterdayStart.getTime());
    System.out.println(
      "Yesterday end:   " + yesterdayEnd +
      "\t Since Epoch:" + yesterdayEnd.getTime());
}If you want to be slightly more efficient, you could take the "yesterdayStart.getTime()" and add (MS_PER_DAY - 1000) to get the yesterdayEndTime (or, even better, use -1 instead of -1000 if you want to get all the way to 11:59:59:999).

Similar Messages

  • How to convert epoch time to datetime in sql*loader Oracle

    Hello,
    I wan't to question how to convert epoch time to datetime in sql*loader Oracle. I try this script for convert epoch time to datetime in sql*loader, but error:
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    This is my loader:
    LOAD DATA INFILE 'C:\Documents and Settings\Administrator\My Documents\XL_EXTRACT_211\load.csv'
    into table TEMP_TEST_LANGY append
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    DATADATA CHAR "TO_DATE('01-JAN-1970','DD-MON-YYYY')+:datadata/86400"
    This is my csv file:
    79314313.7066667
    79314336.2933333
    79314214.3466667
    This is my table:
    CREATE TABLE TEMP_TEST_LANGY
    DATADATA DATE
    Thanks
    Edited by: xoops on Sep 21, 2011 8:56 AM
    Edited by: xoops on Sep 21, 2011 8:58 AM

    thanks for your answer, but I asked to use sql loader instead of the external table, which so my question is why can not the epochtime converted to datetime, if there is no way to convert a datetime epochtime using sql loader, so I'm required to use the external table. thank you.
    This is my error log:
    Column Name Position Len Term Encl Datatype
    DATADATA FIRST * , CHARACTER
    SQL string for column : "TO_DATE('1-Jan-1970 00:00:00','dd-MM-YYYY hh24:mi:ss') + (:DATADATA/60/60/24)"
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Edited by: xoops on Sep 21, 2011 12:33 PM

  • Converting EPOCH time stamp to time stamp in Oracle

    Hi,
    I need a help regarding how to convert the epoch Time stamp, to oracle date and time format.
    for example,
    for epoch time stamp:1204104116656
    the time stamp should be :2008-02-13 12:43:00.351
    Thanks in Advance
    Basil Abraham

    Are you sure you've got the right timestamp? Assuming this is a standard unix epoch time stamp with the epoch date starting at 1970-01-01 UTC the interval between 1970-01-01 UTC and 2008-02-13 is 13922 days, but your epoch timestamp divided by the number of miliseconds in a day 1204104116656/(1000*60*60*24) comes out to 13936.390... days a difference of 14 days 9 hours 21 minutes 56 seconds and 656 miliseconds.
    Anyway to convert you need to convert your epoch date into an interval and add it to the starting epoch date (as a timestamp):
    select to_timestamp_tz('1970-01-01 utc', 'yyyy-mm-dd tzr')+
           numtodsinterval(1204104116656/1000,'second') dstamp
    from dual;Message was edited by:
    Sentinel

  • Year to date of epoch time

    I am doing a report where I would like to select records year to date. My difficulty is that the date field is in epoch time from 1/1/1990. What would be the formula for this record selection? I know I could use yeartodate and dateadd but am having trouble pinning it down. Thank you.

    EPOCH time starts from 01/01/1970 are you sure it is 01/01/1990?
    In your record selection criteria use:
    DateAdd ("s",{epoch.datefield}-18000, #1/1/1970#) in YearToDate
    This checks for Eastern Time, just add 3600 to 18000 for each hour that is behind Eastern Time Zone.

  • How to convert epoch time stamp to timestamp.

    Hi,
    I need a help regarding how to convert the epoch Time stamp, to oracle date and time format.
    for example,
    for epoch time stamp:1204104116656
    the time stamp should be :2008-02-13 12:43:00.351
    Please help me on the same

    SQL> select timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second') from dual;
    TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 09.21.56.656000000 AM
    SQL> select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('EST') from dual;
    (TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 08.21.56.656000000 AM -05:00
    SQL> select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('PST') from dual;
    (TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 06.21.56.656000000 AM -07:00
    SQL> select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('Europe/Berlin') from dual;
    (TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 03.21.56.656000000 PM +02:00
    SQL> select (timestamp '1970-01-01 00:00:00' + numtodsinterval(1204104116656/1000,'second')) at time zone tz_offset('Canada/Mountain') from dual;
    (TIMESTAMP'1970-01-0100:00:00'+NUMTODSINTERVAL(1204104116656/1000,'SECOND')
    27-FEB-08 07.21.56.656000000 AM -06:00SY.

  • How to convert Epoch time to Datetime (YYYYMMDDHH24MMSS)

    Hi,
    In our Oracle db, Datetime is stored as Epoch time (seconds since january 1st 1970). To get a readable date, I have converted those fields as followed:
    TO_CHAR(TO_DATE('19700101000000', 'YYYYMMDDHH24MISS')+((DATE_FIELDS-18000) /(60*60*24)),'YYYYMMDDHH24MISS')
    Result ex: 20100830135422
    The problem is that the resulting fields are in VARCHAR2 instead of DATE so it causes issues in SAP BW reporting development. BW developpers can manage something to make it eventually work but I would like to correct this at the source if it is possible.
    I have already tried to add another "TO_DATE" function at the beginning of the previous expression but I get a date in "DD-MMM-YY" format as a result even if I have forced another date format.
    Any idea on how I could solve this?
    Thanks a lot
    Pascale

    Ok, there is clearly a disconnect here.
    Oracle stores dates in a DATE datatype. This means that, internally, it will store enough information for a 4 digit year, a month, date, hour in 24 hour time, minute, and second. All that information is stored in the DATE datatype inside the database, but, it's stored in an internal format, that has nothing to do with what it will look like when you print it. When you want to retrieve it, Oracle must have a date format string, so that it knows how to display that information. If you do not provide a date format string via the TO_CHAR() function, Oracle has a parameter called NLS_DATE_FORMAT that provides the default format to use. If you have not set the NLS_DATE_FORMAT, it defaults to DD-MON-YY.
    So, having said all that, what are you actually trying to do?
    You started with this expression:
    TO_CHAR(TO_DATE('19700101000000', 'YYYYMMDDHH24MISS')+((DATE_FIELDS-18000) /(60*60*24)),'YYYYMMDDHH24MISS')How is that expression used? In a SELECT statement? Then you probably want it the way it's written above. In an INSERT statement? If so, then if the datatype of the column you're inserting into is DATE, then you probably need to eliminate that outer TO_CHAR conversion, so that the expression returns a date that can be inserted into DATE column.
    Tell us more about what you want to do, and perhaps we can offer further help.
    -Mark

  • Conversion of Standard Datetime format to Unix (Epoch) time

    Hi,
    I am having trouble getting efficient record selection for time ranges on DB2 tables that use the UNIX epoch time stamp.
    E.g., for a 1 minute time range we would currently use SQL such as:
    SELECT * FROM DATABASE.TABLE WHERE  ((TIMESTAMP('1970-01-01-00.00.00.000000') + (("EPOCH_TIME" + 3600000)/1000) SECONDS)>={ts '2008-09-04 14:29:00'} AND (TIMESTAMP('1970-01-01-00.00.00.000000') + (("EPOCH_TIME" + 3600000)/1000) SECONDS)<{ts '2008-09-04 14:30:01'})
    This is the equivalent of:
    select * from DATABASE.TABLE where EPOCH_TIME between 1220534940000 and 1220535000000.
    Now clearly the problem is the top SQL doing a calculation for every record (up to 5,000,000 records) to select the data. It takes approximately 5 minutes to return the data. The bottom SQL takes LESS THAN A SECOND.
    Please, please, please could someone help us with this? We need to be able to enter a datetime variable, and have the SQL sent to the DB2 table in the format of the lower SQL above.
    We are using a BO XI Enterprise server to do this.

    OK Everyone.
    This is how to do it:
    Use the following (for Crystal Reports XI)
    DateDiff (intervalType, startDateTime, endDateTime)
    as:
    Datediff ("s",(datetime(date(1970,01,01)),time(00,00,00)),currentdatetime)
    Looks a bit too simple, but does work. Look out for differences between the results due to daylight saving.

  • Unable to fetch NTP time...?

    Jan 25 15:04:16 unknown dataaccessd[54] <Notice>: 169470|EAS|Error|connection died with error Error Domain=ASHTTPConnectionErrorDomain Code=503 "The operation couldnt be completed. (ASHTTPConnectionErrorDomain error 503.)" 0x1e4d30
    Jan 25 15:04:16 unknown dataaccessd[54] <Notice>: 169470|EAS|Error|ASFolderItemsSyncTask failed: Error Domain=ASHTTPConnectionErrorDomain Code=503 "The operation couldnt be completed. (ASHTTPConnectionErrorDomain error 503.)"
    Jan 25 15:04:16 unknown dataaccessd[54] <Notice>: 169470|EAS|Error|Folder with id 2ce3707e3e43b240ba71254e97e7831d-6865c4 and title Calendar has failed to sync 25 time(s) in a row
    Jan 25 15:04:18 unknown CommCenter[17] <Notice>: Client [com.apple.persistentconnection[dataaccessd,54]] is telling PDP context 0 to go active.
    Jan 25 15:04:19 unknown bootpd[96] <Notice>: service time 0.000048 seconds
    Jan 25 15:04:20 unknown wifid[30] <Error>: WiFi:[349182260.043471]: Client dataaccessd set type to background application
    Jan 25 15:04:28 unknown timed[270] <Notice>: (Note ) CoreTime: NTP timed out with no result
    Jan 25 15:04:28 unknown timed[270] <Notice>: (Warn ) CoreTime: Unable to fetch NTP time.
    Why does this keep coming up in the iPhone Configuration Utility...?

    its just an error message that is being logged.
    The device cannot reach out to ntp.apple.com, my guess your firewall is blocking it.

  • Converting epoch time to a date

    Anyone know of a function to do this. I cant find any in the api and my searches bring up nothing.

    You can create your class that extends GregorianCalendar.Then you can access the protected class in super class. Following codes are what I write to handle this problem. Hope it help.
    import java.util.*;
    public class Test10{
         public Test10(){
              init();
         public void init(){
              MyCalendar calendar1 = new MyCalendar();
              calendar1.set(2002, 07, 12);
              System.out.println("time in epoch: " + calendar1.getTimeInMillis());
         public static void main(String[] str)
              new Test10();
         private class MyCalendar extends GregorianCalendar
              public MyCalendar(){
                   super();
              public long getTimeInMillis()
                   return super.getTimeInMillis();

  • Does labview provide epoch time converter support?

    Hi,
    My product creates a data log file with time stamp. The time stamp is of the epoch format. The system is based on the linux. So I assume that this time stamp is a unix based format. How  should I convert this time stamp data to the UTC format in labview?
    Regards
    Gopal

    LabVIEW's time stamp is the number of seconds since 00:00:00 01/01/1904. Unix (and hence I presume Linux) time is the number of seconds since 00:00:00 01/01/1970, all times specified as GMT. So all you need to do to a Unix timestamp is to add the number of seconds between these two moments in time to obtain the LabVIEW timestamp.
    You can generate this number by using Date/Time to seconds, giving the input as Day 1, Month 1, Year 1970, and all others zero. It gives 2082844800
    Make sure that you treat the numbers as U32, as the current date/time exceeds the maximum value for as signed 32 but value.
    Rod.

  • To fetch response time

    hey..i jus wrote a codo to ping a url but im havon difficulty in developing a code to fetch the response time taken to open that site..can u suggest me some method

    i tried with the method u suggested..it doesn get me the response time of the url
    ..is this the correct way ??
    try{
    System.setProperty("java.net.useSystemProxies","true");
              System.getProperties().put("proxySet", "true");
              System.getProperties().put("proxyHost", "---");
              System.getProperties().put("proxyPort", "---");
              long responseTime = System.currentTimeMillis();
              int requestTime = 0;
              if(responseTime >requestTime+5000){
                   System.out.println("The url is not accessible");
              else
                   System.out.println("ping the url");
              responseTime=requestTime;
              URL yh = new URL("http://www.yahoo.com");
              HttpURLConnection ut =(HttpURLConnection) yh.openConnection();
         ut.setDoOutput(true);
              in = new BufferedReader(new InputStreamReader(ut.getInputStream()));
              String inputLine;
              while ((inputLine = in.readLine()) != null)
                   System.out.println(inputLine);
              in.close();
         }catch(Exception e){
              e.printStackTrace();
    }

  • Data fetch taking time

    hi,
            i have a query that if one has to fetch all the data from heavy tables like faglflexa or bseg the select query takes lots of time and the timeout occurs in foreground.........
                 what should be done in such cases to make it faster....
                  i have a development which requires all the data to be fetched from faglflexa and then comparison for segment is to take place ...this report takes around 2-3 hours to get execute in the background......
                  what approach do the standard tcodes follow when they hit the same tables......
                                               shailendra.

    Hi Sailedhra,
    In this case the best way is to run the report as batch job.
    Second best way is to fetch data in chunks of 1000 records using PACKAGE SIZE addition of select. This will give better performance compared to fetching all the data on huge tables like BSEG.
    Another thing is select on cluster tables is always slower compared to transparent tables. In Standard programs they will use lot of optimization techniques which is not possible for us to analyze and implement the same due to tight dead lines.
    There are many FMs available for replacing selects on cluster tables. Only thing is we have to search and find the appropriate one which suits our requirement.
    Thanks,
    Vinod.

  • Apple Mail fetch repeatedly times out

    This is not a specific Lion problem but has continued under Lion, it's related to Apple Mail. On each of our 4 Macs our mail fetch from our ISP frequently times out  on all POP email accounts, repeatedly asking for a password even though the password is clearly stored in Mail preferences and Keychain. Sometimes I find that the POP email passwords are deleted from Mail, although they are always there in the Keychain. It only happens with POP, not IMAP etc. Needless to say our ISP has been vague and unhelpful. Any suggestions?

    Even if it happens from outside their network, your mail still uses the same settings for servers and ports as to what you put into the settings. So, it's still routed through them regardless of the network your on. That why I suggested it may be the cause. Like I said, the same problem went on with ATT for many months.
    There were many thoughts also on how mac mail was talking to the ISP, but in my case wasn't the problem. If you open up connection doctor in mail and test the connections from time to time, it failed in many cases. Sometimes, it failed constantly.
    And since you've said it happens outside your network, that should eliminate your router.
    So, you may want to talk with your ISP support group and ask them if they are making any changes to ports or servers. And if you haven't, check their website and search for mail server and port settings for mac to make sure you have the latest.
    And I do understand that it's probably a wasted effort because most of the time they won't know what's going on.
    I feel your pain.

  • DataTable (JSF 2.0) - fetching two times

    Hi guys,
    I'm using JSF 2.0. I wanted to use h:dataTable and I realized that the function from value in dataTable is invoked 2 times when I open view in browser.
    I'm confused with that and I don't know what I'm doing wrong. Maybe it's normal behaviour(?). Please help
    @ManagedBean
    public class UserBean {
         private List<String> list=new ArrayList<String>();
         public UserBean() {
              list.add("Tom");
              list.add("Andy");
         public List<String> getList() {
              System.out.println("getList");
              return list;
         public String getString() {
              System.out.println("getString");
              return "String";
    }and view :
    <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
         <title>JSF 2.0</title>
    </h:head>
    <h:body>
         string:
         <h:outputText value="#{userBean.string}" /><br/>
         list:
         <h:dataTable value="#{userBean.list}" var="item"></h:dataTable><br/>
    </h:body>
    </html>Best regards,
    Slawek

    Hi,
    thank you for answer. Problem is not related with displaying value. If I do it :
    <h:dataTable value="#{userBean.list}" var="item">
              <h:column>
                   <h:outputText value="#{item}" />
              </h:column>
         </h:dataTable>I get this output :
    string: String
    list:
    Tom
    Andy
    So everythink seems to be OK ! but .. If I look at tomcat console, I see output:
    [INFO] UserBean:26 - getString
    [INFO] UserBean:21 - getList
    [INFO] UserBean:21 - getList
    [INFO] UserBean:21 - getList
    And this is my problem...
    Any advice ?
    Regards,
    Slawek

  • How to convert epoch time to EST/EDT

    10g sql

    thanks for your answer, but I asked to use sql loader instead of the external table, which so my question is why can not the epochtime converted to datetime, if there is no way to convert a datetime epochtime using sql loader, so I'm required to use the external table. thank you.
    This is my error log:
    Column Name Position Len Term Encl Datatype
    DATADATA FIRST * , CHARACTER
    SQL string for column : "TO_DATE('1-Jan-1970 00:00:00','dd-MM-YYYY hh24:mi:ss') + (:DATADATA/60/60/24)"
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Edited by: xoops on Sep 21, 2011 12:33 PM

Maybe you are looking for

  • Sata 1-2 Raid 0 to 3-4?

    can i safely put my drives on 3 and 4 without loosing all the data? only reason i am doing this is because i can't overclock at all.....i've heard the sata ports limit the overclock..therefore changing them.

  • Where to download the appropriate JDK for Windows 64 bits ?

    Hi nice people, i have donwloaded the latest version of SQL developr for x86-64 bits. The JDK is not bundled with. A link is provided for downloading it. I have downloaded Java SE 7. But sqldeveloper did not not like it he said something like, this i

  • IMessage Not Working Since Mountain Lion Upgrade

    Since I "upgraded" my iMac and MacBook Air to Mountain Lion, iMessage delivery is hit and miss to the say the least from my iPhone 4S.  I first realised there was an issue receiving text messages whilst in the States and not connected to WiFi. Messag

  • Can you load Illustrator 8.0 on Windows 7 64 bit operating system?

    I just bought a new Dell Desktop that has Windows 7 64 bit operating system. My old version of Illustrator 8.0 at Set Up will not load ? Is there a work around for 64 bit ? please try an e-mail to [email protected]

  • Error Handler Approach / Road forward

    Is there a way to give move verbose/specifc error messages apart from the Generic Error Message for errors which occur during save/retrieve? For example, in case of OPA Siebel connector - display a specifc error message stating the failure was due to