开发者

Android Emulator Returns Wrong Date

开发者 https://www.devze.com 2023-01-28 00:10 出处:网络
I am trying to get the date in Android using this code final Date df = new Date(); 开发者_StackOverflow中文版final DateFormat dft;

I am trying to get the date in Android using this code

        final Date df = new Date();
    开发者_StackOverflow中文版    final DateFormat dft;
        dft = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
        final String  dftX = dft.format(df).toString();

This works but it returns as 11/03/10 instead of 12/03/10. The emulator appears to be showing the correct date. What am I doing wrong?

Rick


As far as I know, you must add a "+1" to your month because in Date conversion the counting month begins with "0" as Jan and ends with "11" for Dec

0

精彩评论

暂无评论...
验证码 换一张
取 消