How can i get current time of a given timezone

how can i get current time of a given timezone
for example: Asia/Hong_Kong
my code is like this, but the result is not correct.
what's wrong?
import java.util.*;
public class test {
public static void main(String[] args){
          String s = "Asia/Hong_Kong";
          String tempS = "";
          TimeZone myTime = new SimpleTimeZone(s);
          //TimeZone myTime = TimeZone.getTimeZone(s);
          Calendar myCal = new GregorianCalendar(myTime);
          tempS = myCal.get(Calendar.YEAR)+"-"+
                    (myCal.get(Calendar.MONTH)+"-"+
                    myCal.get(Calendar.DATE)+" "+
                    (myCal.get(Calendar.HOUR)+":"+
                    myCal.get(Calendar.MINUTE)+":"+
                    myCal.get(Calendar.SECOND);
          System.out.println(tempS);
output is : 2001-7-15 11:16:48
but the correct time should be: 2001-8-16 7:17:48
the correct time should be 2001-8-16

Certain indexes in the Calendar API start at 0 rather then 1, so, when you get the value, you may want to increment.
I'm not sure why the time is incorrect. You may want to call getAvailableIDs() and make sure that the desired TimeZone ID is supported by your version. I doubt that Sun would have incorrect support for the time zone, but it may not be included, or perhaps it is included with a diffrent ID. You can always create your own time zone as well, by passing the String offset to getTimeZone(), the offset being how many hours beyond or before GMT. Hopefully this helps.

Similar Messages

  • How can i get current time in different TimeZone

    Hi alls,
    How can i get current time in different TimeZone.
    I've tried
    final Calendar calendar = Calendar.getInstance(GMT0_TIME_ZONE);
    final Date date = calendar.getTime();
    but it returns current time in my time zone not in GMT0

    a simple way would be:Sometimes gets you the right result (not during daylight saving), but always the wrong way.
    I would strongly recommend getting into the habit of handling Dates correctly. A Date is a universal instant in time - the number of milliseconds since midnight GMT on 1 January 1970. That instant corresponds to various dates and times, depending on your time zone and the effect of daylight saving. You make that conversion of a universal instant to a localized date/time using Calendar and DateFormat.

  • How can we get current time date with resultset?

    Dear All,
    I have to insert current time date in the table.So,i need to get the current time and date with result set.So,I will first get the time date and then insert it into the table.
    I know how can we get current time and date without resultset.i have created this function its working.But now i want to use this.mean using resultset i want to put in the table.
    How can i do this?
    public static String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
    public static String now() {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
    return sdf.format(cal.getTime());
    }

    yuck. Why not simply set a "new java.sql.Date()" to the SQL parameter in question?

  • How can i get the time to appear on my stored data in notepad

    Hi all,
    I was wondering how can i get the time to appear on my stored data in notepad? I saw an example before but i forgotten which example was it.. Any ideas??
    holla
    Attachments:
    TextFile1.txt ‏3 KB

    Hi
    Im using Labview 8.2. Currently it just shows the data without the time. Im not sure what to do. It works perfectly though. I just want the time to appear on my notepad along with my data
    holla
    Attachments:
    Testing1.txt ‏1 KB
    Untitled 231_LV80.vi ‏23 KB

  • How can I get my time machine to allow me to recover files again? After upgrading to OS X, the time machine still backs up the files; but, I'm not able to navigate within the time machine or select any folders or files for restore.

    How can I get my time machine to allow me to recover files again?
    After upgrading MBA to OS X, the time machine still backs up the files; but, I'm not able to navigate within the time machine or select any folders or files for restore.
    I've searched and can not find a solution to the problem that's being encountered.

    Yeap that all makes sense now.
    Do you only have the current backup showing in the TM display?? Won't it fill in the rest?
    Over wireless are you waiting for the indexing to finish.. ??
    Previous backup may not show for a couple of hours.
    Long short of it.. Mavericks version of TM is a pain.
    Sometimes it is easier to completely ignore the TM backup and do the restore manually.
    I have posted the details here. See if this helps.
    Can't access old files on time capsule

  • How can I get a time stamp on text message without turning on "read"???

    How can I get a time stamp on text message iPhone 5 IOS 7? (Without having to send read receipt)

    You can make the "Visit Date" column visible in the Bookmarks Manager (Library) via "Views > Show Columns"
    * Bookmarks > Organize Bookmarks
    *http://kb.mozillazine.org/Viewing_the_browsing_history_-_Firefox

  • How can i get the time and result together show in one Array or in Cluster?

    hello everyone i am a new user .I want to get the time and voltge form a Generater. How can i get the time and result together show in one Array or in Cluster?When i selecte the first(or third...) result then in the front panel display the time and the voltge.Thank you!
    I post the time and voltge NOT together photo
    Attachments:
    12345.GIF ‏54 KB

    You can create an array of clusters with one element being the time and the other being the voltage, like so (using the "Get Waveform Components" function):
    Message Edited by smercurio_fc on 10-17-2007 03:15 PM
    Attachments:
    pic.PNG ‏11 KB

  • How can I get the time in Microsecond with JNI ?

    How can I get the time in Microsecond with JNI ?

    JNIEXPORT jdouble JNICALL Java_Win32Native_queryPerformanceFrequency (JNIEnv *env, jobject obj) {
         LARGE_INTEGER lFrequency;
         ::QueryPerformanceFrequency(&lFrequency);
         return (jdouble)lFrequency.QuadPart;
    JNIEXPORT jdouble JNICALL Java_Win32Native_queryPerformanceCounter (JNIEnv *env, jobject obj) {
         LARGE_INTEGER lpCounter;
         ::QueryPerformanceCounter(&lpCounter);
         return (jdouble)lpCounter.QuadPart;

  • How can I get my Time Capsule to show up in finder?

    How can I get my Time Capsule to show up in finder?

    An alternate, and simpler method for most users is to open any Finder window, then look for the Time Capsule icon under the Shared heading on the left side of the window.
    When you click on the Time Capsule icon, a folder......named "Data", unless you have changed the name of the drive.....will appear to the right.
    Double-click "Data" to mount the Time Capsule drive on the desktop, where you can now drag/drop or copy/paste data to the drive.
    If the Time Capsule does not appear under the Shared heading when you open a Finder window......then you are likely using the Yosemite operating system on your Mac, and it will take some work to find it.
    In that case, Niel's method might be the better way to go.

  • In version 3.x.x I used to be able to type search terms into the address bar and the page would load, similar to Google's "Feeling Lucky" button. Now it just brings up a Google search for the terms I typed in. How can I get this time saving feature back?

    In version 3.x.x I used to be able to type search terms into the address bar and the page would load, similar to Google's "Feeling Lucky" button. Now it just brings up a Google search for the terms I typed in. How can I get this time saving feature back?

    The change between Firefox 3.6.* and Firefox 4 is how location bar search works. In Firefox 3.6 it uses Google "Browse by name" search. With the browse by name search, it performs a Google search and if there is a clear match it will take you to the site, otherwise it shows the Google search result. With Firefox 4 it just performs a Google search if you type something which is not recognised as a URL.
    To get the Firefox 3.6 behaviour on Firefox 4 you need to change a hidden preference.
    # Type '''about:config''' into the location bar and press enter
    # Accept the warning message that appears, you will be taken to a list of preferences
    # Locate the preference '''keyword.URL''', double-click on it and change its value to the link shown below
    [http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q= http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q=]
    If you prefer, you can also do this by installing the Browse by Name extension - https://addons.mozilla.org/firefox/addon/browse-by-name

  • How can I get file list for a given directory?

    Hi,
    How can I get file list for a given directory? Is there a function?
    Thanks.

    Hi friend,
    Try this sample report. It displays all files in a directory.
    While executing give some directory name in input. ex:  C:\
    Mention file type in filter parameter. ex: *.DOC
    REPORT ztests.
    DATA : file_table LIKE TABLE OF sdokpath WITH HEADER LINE .
    DATA : dir_table LIKE TABLE OF sdokpath WITH HEADER LINE .
    PARAMETERS:p_dir(50) TYPE c.
    CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
      EXPORTING
        directory  = p_dir
        filter     = '*.DOC'
      TABLES
        file_table = file_table
        dir_table  = dir_table
      EXCEPTIONS
        cntl_error = 1
        OTHERS     = 2.
    LOOP AT file_table .
      WRITE:/ file_table-pathname.
    ENDLOOP.
    Might be helpful...
    Thanks.....
    Edited by: Guest77 on Feb 11, 2009 5:30 AM

  • How can i get system time and day

    How can i get the system current time and save it into a variable, then get the current day like wednesday and save it into another variable. Can someone teach me how to set this. thanks
    regards,
    albert

    How can i get the system current time and save it
    into a variable, then get the current day like
    wednesday and save it into another variable. Can
    someone teach me how to set this. thanks
    regards,
    alberti've managed to do this but in gui format hope it suites you.
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class time{
         private Container content;
              private JTextField timeField, dateField;
         public static void main (String[]args){
              time t = new time();
              t.TextClockWindow();
              t.showGUI();
         public void TextClockWindow() {
    // Build the GUI - only one panel
    JFrame frame = new JFrame();
    content = frame.getContentPane();
    timeField = new JTextField(6);
    timeField.setFont(new Font("sansserif", Font.PLAIN, 20));
    dateField = new JTextField(6);
    dateField.setFont(new Font("sansserif", Font.PLAIN, 20));
    content.setLayout(new FlowLayout());
    content.add(timeField);
    content.add(dateField);
    // Create a 1-second timer and action listener for it.
    // Specify package because there are two Timer classes
    javax.swing.Timer t = new javax.swing.Timer(1000,new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Calendar now = Calendar.getInstance();
    int h = now.get(Calendar.HOUR_OF_DAY);
    int m = now.get(Calendar.MINUTE);
    int s = now.get(Calendar.SECOND);
    //String ampm =now.get(Calendar.AM_PM);
    int y =now.get(Calendar.YEAR);
    int mon=now.get(Calendar.MONTH);
    int d=now.get(Calendar.DAY_OF_WEEK);
    dateField.setText(""+y+ ". "+mon+ "."+d);
    timeField.setText("" + h + ":" + m + ":" + s);
    //to dispaly the current date so easily;stvworks
    String rightNow = "" + new Date();
    t.start(); // Start the timer
    }//end constructor
    public void showGUI(){
         JFrame frame = new JFrame("Time Frame.");
              frame.add(content);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
    frame.setResizable(false);
    frame.setVisible(true);

  • How can I get a time stamp in the historyfile

    I can´t see date and time in the history file, how can I get that information on a MAC ?

    You can make the "Visit Date" column visible in the Bookmarks Manager (Library) via "Views > Show Columns"
    * Bookmarks > Organize Bookmarks
    *http://kb.mozillazine.org/Viewing_the_browsing_history_-_Firefox

  • How can I get the time for a simulate signal express vi waveform?

    I tried converting to an array and then indexing, but every index I try only gives me the y value. See attached VI for clarification on what I mean.
    Attachments:
    simulate signal.vi ‏49 KB

    You will have to keep track of that yourself.  You are sampling at 360kHz.  This means that each sample is ~2.8us.  You can easily get the time by taking that dt (2.8us) multiplied by the sample index and adding the time at which the first sample was taken.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How can I get sigalg attribute from a given X509 certificate

    Hi,
    I am verifying my client's digigital signature like this
    String sigalg = "SHA1WithRSA";
    Signature sig = Signature.getInstance(sigalg);
    sig.initVerify(pubKey);
    sig.update(sEnvelope.getBody().toString().getBytes());
    return sig.verify(Base64.decode(sigValue));
    while getting signature instance, rightnow I am hardcoding that to "SHA!withRSA", because I know that client is comming with that signatureAlgorithm, If another client comes with another alogorithm say "MD5withRSA", it is going to be failed. how can I change that sigAlg variable dynamically, based on different signature ?? what I have from the client is certificate file. how can I get signature algorithm from the certificate or from publicKey object ??
    Thanx, Venu

    Check the following methods in X509Certificate:
    getSigAlgName
    getSigAlgOID

Maybe you are looking for

  • Partial reversal of a goods receipt from process order

    Dear All Could anyone please help me with explaining how to do a partial reversal of a goods receipt from process order? If Iu2019m using trans CORS I have to cancel the entire operation, which I donu2019t want to do. If Iu2019m using MIGO and MT 102

  • Not correctly formating an xref tag

    On my project conversion settings, I have a setting for the cross-reference Section on Page that is set to map as "Para Text" on page #  to Para Text in RoboHelp. Theoretically, this should eliminate the page numbers. However, it isn't happening. I'v

  • In iPhoto the option to edit in photoshop elements  has vanished

    The option in iPhoto>pref>advanced>Edit in>Iphoto or PSE (Photshop Elements) has vanished!! My only option now is to edit in iPhoto or iPhoto library!! I usually edit my RAW files in ACR which has always opened when I hit edit in IPhoto,,, Help!! Doe

  • Selection from Input help different from PA30 IT0014

    Hi Guys, Need advise as i'm trying to get the same result data from input help in IT0014 (wage type). I'm using normal selection from table but the result set are diffrent. I'm noticed more value appeared than the input help in IT0014 PA30. I checked

  • Commands used in obiiee

    anyone give me the commands list used in putty for the server? like cd,start and stop...(anybody gave me the all the commands and purpose of those commnds and if posssible give me the example?) Thanks in advance...