Android Convert Central Time to Local Time

后端 未结 4 1751
星月不相逢
星月不相逢 2020-12-30 16:43

I have a MySql database that stores a timestamp for each record I insert. I pull that timestamp into my Android application as a string. My database is located on a server

4条回答
  •  遥遥无期
    2020-12-30 17:10

    This is an old question, but I want to write my answer. Assume, the timestamp you get from SQL is like the following format: yyyy-MM-dd'T'HH:mm:ss

    public static Date convertStringToDate(String strDate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("CST"));
        return sdf.parse(strDate);
    }
    

提交回复
热议问题