I have the following code below in the server stored as gmt and would like it to change based on android device timezone.I am getting wrong value unable to figure out the mistake.I really appreciate any help.
Thanks in Advance.
public class MainActivity extends Activity {
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String d="2014-01-14 16:28:50";
t=(TextView)findViewById(R.id.textView1);
Timestamp ts = Timestamp.valueOf(d);
long tsTime1 = ts.getTime();
String r=getDate(tsTime1);
t.setText(r);
}
private String getDate(long timeStamp){
SimpleDateFormat objFormatter = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
objFormatter.setTimeZone(TimeZone.getDefault());
Calendar objCalendar =
Calendar.getInstance(TimeZone.getDefault());
objCalendar.setTimeInMillis(timeStamp*1000);//edit
String result = objFormatter.format(objCalendar.getTime());
objCalendar.clear();
return result;
}
}