我已编写此代码以将当前系统日期和时间转换为其他时区.我没有收到任何错误,但我没有按预期得到我的输出.就像我在特定时间执行我的程序..我的输出是::
印度当前时间是::Fri Feb 24 16:09:23 IST 2012
:: Central Standard Time中的日期和时间::Sat Feb 25 03:39:23 IST 2012
根据CST时区的实际时间是::
Friday, 24 February 4:39:16 a.m(GMT - 6:00)
Run Code Online (Sandbox Code Playgroud)
所以有一些时间差距.我不知道为什么会这样.任何帮助将不胜感激..代码是::
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"); …Run Code Online (Sandbox Code Playgroud)