Note that there are some explanatory texts on larger screens.

plurals
  1. PODate and time conversion to some other Timezone in java
    primarykey
    data
    text
    <p>i have written this code to convert the current system date and time to some other timezone. I am not getting any error but i am not getting my output as expected. Like if i execute my program at a particular time.. My output is :: </p> <p>The current time in <strong>India</strong> is :: <code>Fri Feb 24 16:09:23 IST 2012</code></p> <p>The date and time in :: <strong>Central Standard Time</strong> is :: <code>Sat Feb 25 03:39:23 IST 2012</code></p> <p>And the actual Time according to <strong>CST time zone</strong> is :: </p> <pre><code>Friday, 24 February 4:39:16 a.m(GMT - 6:00) </code></pre> <p>So there's some <strong>time gap</strong>. and i don't know why this is happening. Any help will be appreciated.. The code is :: </p> <pre><code>package MyPackage; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Temp2 { public static void main(String[] args) { try { Calendar currentdate = Calendar.getInstance(); String strdate = null; DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); strdate = formatter.format(currentdate.getTime()); TimeZone obj = TimeZone.getTimeZone("CST"); formatter.setTimeZone(obj); //System.out.println(strdate); //System.out.println(formatter.parse(strdate)); Date theResult = formatter.parse(strdate); System.out.println("The current time in India is :: " +currentdate.getTime()); System.out.println("The date and time in :: "+ obj.getDisplayName() + "is ::" + theResult); } catch (ParseException e) { e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload