Getting current date and timestamp for timezone

I am getting the current date and timestamp using
Date d = new Date();
On the platform I'm using it is returning it in GMT time.
I want to convert this into Eastern Time Zone for United Status.

java.util.Date objects contain a count of milliseconds since the "epoch", which happens to be midnight, Jan 1 1970 GMT. However, they aren't intrinsically "in" any timezone.
If you simply call Date.toString(), you'll get the date formatted for the current locale, including timezone.
If you want a different format, you can use the DateFormat or SimpleDateFormat classes (recommended), or use Calendar to pull the various date components out. You have to physically set the timezone for each of these.
To get a list of timezones supported by your machine, you can run this program:
import java.util.Arrays;
import java.util.TimeZone;
public class TZDump
    public static void main(String[] argv)
    throws Exception
        String[] zones = TimeZone.getAvailableIDs();
        Arrays.sort(zones);
        for (int ii = 0 ; ii < zones.length ; ii++)
            System.out.println(zones[ii]);
}And, here's a program that lets you compare the same date in different timezones:
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class TZDemo
    public static void main(String[] argv)
    throws Exception
        SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
        Date now = new Date();
        System.out.println("Default TZ = " + fmt.format(now));
        String[] zones = new String[] { "EST", "EST5EDT", "PST"};
        for (int ii = 0 ; ii < zones.length ; ii++)
            fmt.setTimeZone(TimeZone.getTimeZone(zones[ii]));
            System.out.println("EST        = " + fmt.format(now));
}

Similar Messages

  • Problem with getting current date and time using oracle.jbo.domain.Date

    I`d like to get current date and time using oracle.jbo.domain.Date method getCurrentDate(), but it always return current date and 12:00:00. I also need to get the current time.

    I think you should use java.sql.Timestamp domain.
    (And set database type to TIME or DATETIME.)
    Jan

  • Get  current date and time

    hello.
    How can I get current date and time in JAVA?
    Thanks.

    Sorry, I mean:
    how can I get the value of DATE, MONTH, and YEAR of the
    current date?
         Date date = new Date();
         System.out.println(date);

  • Getting Current Date and using it in SQL

    How do you get a current time and store it in a variable..
    I am trying to make an a SQL query using it to search for all previous days appart from today.
    ex:
    currentDate = // store current  date as a ShortDate into a variable
    query = "SELECT * FROM Table WHERE < DATES "+currentDate+" ORDER BY Id"";

    Regarding prepared statement .
    I am trying to insert the date into a variablelike
    below.
    String date = newjava.sql.Date(myDate.getTime());
    I want allow me .... there really has to be a wayto
    get a current System Date within java.That is because you have a lot of errors in that
    line..
    java.sql.Date now = new
    java.sql.Date(System.currentTimeMillis());If you want it as a sql date object (date object in
    sql doesn't have a time field, you need to use
    Timestamp if you want date and time)
    /Kajjava.sql.Date now = new java.sql.Date(new java.util.Date().getTime());

  • How does BR get current date, user, and associate member with Attribute Dim

    I need use Business rules or Calc script to implement following functions:
    1. Get current date and the name of user who is running the BR and save the information to cube.
    I don't find any functions to get current date and users.
    Also, since text and date is store in relational database and essbase cube only stores the index, it looks that the value can't be changed or stored by using "==" directly, is there any function to change value of members with Text or Date types in BR/Calc script?
    2. End users select attribute value (via smart list) of products or projects(Sparse dimensions) in data form, run BR to update the association of these members with attribute dimension.
    I don't find any functions to change the attribute association in BR/Calc, is there any CDF (Custom Defined Function) that can do it?
    Thanks!

    Hi,
    For the date functionality, check out the post below.
    Re: Days behaviour between two dates
    As for the username, there is a little tricky way that requires an unused or a new dimension along with a smart list of user names. It's also possible to capture the user name from the cookies and pass it on to the form. The latter is possible through validatedata.js however requires hefty coding here and there.
    As for the attributes, it's not possible to update metadata through business rule. So no luck in there.
    Cheers,
    Alp

  • Odd Date for Current Date and Time

    I am modifying a column in a list to get current date and time using =TODAY()+NOW() in the calculated field and get a time that is behind by 1 hour but the date is 4 months 114 years ahead (2128). How can I fix this field?

    http://sharepointsolutions.com/sharepoint-help/blog/2011/04/how-to-add-and-subtract-hours-and-minutes-from-date-and-time-fields-in-sharepoint-lists/

  • What is the best way to captue current date and time?

    I got a field in table to capute current date and time...i am
    using SQL Server.
    field name datatype length
    enter_datetime datetime 8
    What is the best way to get current date and time and insert
    to table?.
    Is this way?.
    <cfset curtime = 'dateformat(#now()#,'mm/dd/yyyy')&"
    "&timeformat(#now()#,'hh:mm:ss')'>
    This way looks like time is not entered correctly.
    or any other better way?.

    > get current date and time and insert to table?
    You can use cfqueryparam
    <cfqueryparam value="#now()#"
    cfsqltype="cf_sql_timestamp">
    Or as was suggested, set the default for your table column to
    getdate(). Then you won't have to insert anything. Sql server will
    do it automatically when a new record is created.

  • Timezone effects on Date and Timestamp fields in af:query component

    Hello,
    I'm working on an ADF application where time zone is configured as follows:
    * Dynamic View Layer time zone is configured in trinidad-config.xml file and bound to a session scoped value:
    <trinidad-config>
      <skin-family>fusionFx</skin-family>
      <time-zone>#{sessionScope.tz}</time-zone>
    </trinidad-config>* ADF BC time zone is configured in adf-config.xml file and bound to View Layer time zone:
    <adf-config>
      <user-time-zone-config xmlns="http://xmlns.oracle.com/adf/usertimezone/config">
        <user-timezone expression="#{adfFacesContext.timeZone.ID}"/>
      </user-time-zone-config>
    </adf-config>The problem here is that Dates and Timestamp values work as expected all over the application except for the af:query component. When displayed as af:inputDate in af:form, Dates and Timestamp values are NOT getting converted to the time zone (TZ) configured in trinidad-config.xml file, whereas TimestampTz and TimestampLtz are. However, when displayed in af:query component, Dates and Timestamp values are automatically converted to View Layer TZ after a search has been performed.
    For example, say View Layer TZ = US/Pacific and we enter 01/jun/2011 as a search criteria of type Date and then click on the Search button. The displayed value automatically changes to 25/nov/2011, that is, it gets converted to the WLS JVM time zone, which is set to Europe/London.
    Is conversion of Date and Timestamps in af:query component the expected behaviour or could this be a bug?
    Is there any way to avoid this conversion?
    Thanks in advance
    Version:
    ADF Business Components 11.1.1.59.23
    Java(TM) Platform 1.6.0_21
    Oracle IDE 11.1.1.4.37.59.23
    PMD JDeveloper Extension 4.2.5.3.0
    Repost on 26-nov-2011 9:29
    Repost on 28-nov-2011 15:10
    Edited by: Barbara Gelabert on 26-nov-2011 9:29
    Edited by: Barbara Gelabert on 28-nov-2011 15:10

    Hi,
    Thanks for your reply. This certainly seems promising. However, I am getting a connection error now.
    The following...
    jar_loaded = require 'ojdbc14.jar'
    puts "Oracle jar loaded? #{jar_loaded}"
    puts "Starting active record"
    require 'rubygems'
    gem 'activerecord'
    gem 'activerecord-oracle_enhanced-adapter'
    require 'activerecord'
    puts "Connecting to MXGN"
    ActiveRecord::Base.establish_connection(
    :adapter => 'oracle_enhanced',
    :host => 'THEHOST',
    :port => '1550',
    :database => 'THEDB',
    :username => 'THEUSER',
    :password => 'THEPASSWORD'
    ... produces
    Oracle jar loaded? true
    Starting active record
    Connecting to MXGN
    ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install ojdbc14.jar library.
    ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install ojdbc14.jar library.
    C:/jruby/jruby-1.2.0/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `establish_connection': Please install the oracle_enhanced adapter: `gem install activerecord-oracle_enhanced-adapter` (LoadError) (RuntimeError)
    from H:\sandbox\DBPlay\lib\main_enhanced.rb:12
    I'm confused. Am I missing the driver, or have I failed to setup the enhanced Oracle adapter?
    I have tried moving the jar to $JRUBY_HOME/lib too, but the result was the same.
    All help would be greatly appreciated.
    Many Thanks
    Adrian

  • How to get current time and date??

    How to get current time and date from my PC time and date to the java application??
    i use java.util.* package but got error, that is:
    - java.util.* and java.sql.* class are match
    - abstract class cannot be instantiated
    so what can i do, pls guide...thanks...

    There is a method in the System class that will return the current system time. You could also instantiate a Date, Time, Timestamp, or Calendar object, all of which get created with the system time by default.
    Don't import *. Import the specific classes you need.
    Next time, post the actual text of the exceptions/compile errors. If you make people guess, most just won't bother.

  • Get the Current Date and Time of a Location

    I have created a windowsPhoneApplication in silverLight 8.1.In my application,I have to upload videos on some server.The Uploading get failed If the Date and Time settings of my device is not the current Date and Time.So How can I get the current date
    and time even if the device settings is wrong?

    Hi shifana,
    Do you know server's time zone? If yes, you can manually translate to the correct time zone.
    Otherwise try some online time acquire API.
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Current date of birth for my column is null getting error....

    Hi All..
    i am calucating the current date of birth for my column which is date field and accept nulls (cust_dob) in my table.
    select cust_dob,Add_Months(
    to_date(cust_dob, 'dd/mm/yyyy'),
    Months_Between(
    trunc(sysdate, 'year'),
    trunc(to_date(cust_dob, 'dd/mm/yyyy'), 'yyyy')
    ) as current_dob from m_customer_hdr
    when i execute my query in toad. it is showing the result. but when i scroll down to see data it thow error as
    ORA-01858: a non-numeric character was found where a numeric was expected...
    Thanks in advance..
    Abdul rafi

    What datatype is cust_dob datatype. Somehow I have a feeling it is DATE. If so, expression:
    to_date(cust_dob, 'dd/mm/yyyy')Implicitly converts cust_dob to a string using session nls_date_format and then converts it back to date using 'dd/mm/yyyy' format. Now if NULL dob are fetched first, you might get something like:
    SQL> ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-RR';
    Session altered.
    SQL> SET SERVEROUTPUT ON
    SQL> BEGIN
      2      FOR v_rec IN (SELECT  TO_DATE(cust_dob,'mm/dd/yyyy') cust_dob
      3                      FROM  (
      4                             SELECT TO_DATE(NULL) cust_dob FROM DUAL UNION ALL
      5                             SELECT TO_DATE(NULL) cust_dob FROM DUAL UNION ALL
      6                             SELECT TO_DATE(NULL) cust_dob FROM DUAL UNION ALL
      7                             SELECT sysdate cust_dob FROM DUAL
      8                            )
      9                   ) LOOP
    10        DBMS_OUTPUT.PUT_LINE('DOB = "' || v_rec.cust_dob || '"');
    11      END LOOP;
    12  END;
    13  /
    DOB = ""
    DOB = ""
    DOB = ""
    BEGIN
    ERROR at line 1:
    ORA-01858: a non-numeric character was found where a numeric was expected
    ORA-06512: at line 2So if column CUST_DOB is DATE, use:
    select cust_dob,Add_Months(
    cust_dob,
    Months_Between(
    trunc(sysdate, 'year'),
    trunc(cust_dob, 'yyyy')
    ) as current_dob from m_customer_hdrSY.

  • How to get the current data and time of SCOM server via SCOM SDK (API) calls?

    Hi,
    I need to read the current date and time of SCOM server via SOM SDK.
    Is there a class in SDK that provides this info ?
    Thanks,
    satheesh

    To get time and date of Alerts of SCOM, You can use following command let "get-scomalert"
    Also, You can refer below links
    http://blog.tyang.org/2013/02/21/using-scom-2012-sdk-to-retrieve-resource-pools-information/
    Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question, please click "Mark As Answer"
    Mai Ali | My blog: Technical

  • PowerShell Script to get the details Like Scope,Last Deployed date and Name for a Solution Deployed in the Farm.

    Hi Experts,
    I am trying to  build a PowerShell Script to get the details Like Scope,Last Deployed date and Name for a Solution Deployed in the Farm.
    Can anyone advise on this please.
    Regards

    Get-SPSolution|Select Name,Scope,LastOperationResult,LastOperationEndTime|Export-CSV "SPInstalledSolutions.csv" -NoTypeInformation
    SPSolution properties
    Get-SPSolution
    This post is my own opinion and does not necessarily reflect the opinion or view of Slalom.

  • Current date as deafult for Calender Day and user entry

    Hello All,
    There is a select option for Calender Day for a BW query.
    This Calender Day should have a default as Current Date and User entry is also possible.
    I have used a Customer exit and written the following code under i_step = 1
    data: v_currdt like sy-datum.
    clear: v_currdt, vfl_range.
             if i_step = 1.
              vfl_range-sign = 'I'.
              vfl_range-opt = 'EQ'.
              v_currdt = sy-datum.
              vfl_range-low = v_currdt.
              append vfl_range to e_t_range.
             endif.
    Please inform if this code is incorrect, because I am not able to see the date at all.
    Cheers,
    KP

    Hi
    Check with this code!
    Implemented for the same function as you require.-
    if i_step = 1.
      case i_vname.
        WHEN 'ZZZZZZ'.
          IF i_step = 1.
            REFRESH e_t_range.
            CLEAR l_s_range.
            l_date1 = sy-datum.
            L_S_RANGE-LOW = l_date1.
            L_S_RANGE-SIGN = 'I'.
            L_S_RANGE-OPT  = 'EQ'.
            APPEND L_S_RANGE  TO E_T_RANGE.
          endif.
      endcase.
    endif.
    Regards
    M.A

  • How to get current date for posting date

    hi,
    how to get current date for posting date ? any sample code ?
    Thanks

    Hi......
    Use
    Select getdate()
    for current date.......
    Regards,
    Rahul

Maybe you are looking for

  • Creation of super bom-- mrp run

    Dear Friends, i want to create one super bom for any fert. what i understand from super bom is that, it defines all possible components(bom data). when we require specific type of product, we have to consider some of the components relevant to the pa

  • Problem with reinstalling os x tiger

    I am attempting to reinstall my operating system to get the laptop back to factory condition. When putting the install disc in and starting the install process I click restart. Then the computer restarts and the process immediatly goes to a screen as

  • Video Wont play...cant find answer

    I converted the video, loaded on iTunes, it plays on iTunes, loaded on my iPod, but when I click play it goes to a black screen for about 15 seconds, then goes back to the list of movies. No sound or anything plays. It is listed as a movie, my TV oup

  • Error message when uploading- but document still uploads

    Hi, Over the past few days I've gotten an error message when uploading a document to my SharePoint site (O365/ 2013). All the error message says is "Sorry, something went wrong. An unexpected error has occurred." The correlation ID is 379ed19c-706a-1

  • Writing XMP Thumbnail Metadata to AE Preset

    Hi guys. I am working on a After Effects script to basically insert a gif as metadata into a fx preset file. If you open Adobe bridge and browse to the After effects text presets you will see that you can click on a preset and in the preview there is