我怎样才能获得洛杉矶(美国)当前时间编程在android系统? [英] how can i get Los Angeles (USA) current time programmatically in android?

查看:388
本文介绍了我怎样才能获得洛杉矶(美国)当前时间编程在android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我开发android系统中的应用一。我需要使用的洛杉矶(美国)位置的当前时间,日期。对于我用下面的code

 日历日历= Calendar.getInstance();
        时区TZ = TimeZone.getTimeZone(美国/洛杉矶);
        calendar.setTimeZone(TZ);
        字符串s = calendar.getTime()的toString()。

但它是给当前位置的时间和日期。请提供code。通过像洛杉矶,提供特定地点的名称来获得时间和日期。


解决方案

 日历日历= Calendar.getInstance();
            SimpleDateFormat的SDF =新的SimpleDateFormat(DD-MMM-YYYY HH:MM:SS Z);
            sdf.setTimeZone(TimeZone.getTimeZone(美国/洛杉矶));
            的System.out.println(sdf.format(calendar.getTime()));

仅供参考,日期无非是特定的瞬间更多的时间。

Hi i developing a application in android. i need to use the Los Angeles (USA) location current time, date. For that I used the below code

        Calendar calendar = Calendar.getInstance();       
        TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
        calendar.setTimeZone(tz);
        String s=calendar.getTime().toString();

But it is giving the current location time and date. Please provide a code to get the time and date by providing particular location name like Los Angeles.

解决方案

            Calendar calendar = Calendar.getInstance();       
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z");
            sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
            System.out.println(sdf.format(calendar.getTime()));

FYI , a Date is nothing more than a specific instant in time .

这篇关于我怎样才能获得洛杉矶(美国)当前时间编程在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆