How to get time format using country ISO code in android?

I am working on simple application to show the time in different formate. To show the time I am displaying ISO country code using this ISO code. Can I able to change time in that ISO country format?

I have written code as follows

TelephonyManager tMgr = 
    (TelephonyManager)getApplicationContext().getSystemService(
        Context.TELEPHONY_SERVICE);

String iso = tMgr.getNetworkCountryIso();
Log.v("Device iso", "=======>" + iso);
String mbNo = tMgr.getLine1Number();
Log.v("mbNo", "=======>" + mbNo);

Here I am getting iso as US. Can I show the current system time format in US time format?

I have used Date class to show time as follows

DateFormat df = DateFormat.getTimeInstance();
systime = df.format(new Date());

It is displaying time in HH:MM:SS AM/PM format. I would like to display the above time as US format.

How can I display the time in US or any other format?

Answers


In your case I think you could use

Date systemDate = Calendar.getInstance().getTime(); // the current system time
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT, Locale.US);
Date myDate = df.format(systemDate);

Or to use custom format

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date myDate = sdf.format(systemDate);

if you have a string use parse

Date myDate = sdf.parse("29/04/1980 12:30:24");

DateFormat has a static method that can initalize a localized format.


I believe that you need to create your own method for US format. Try to create a class and make its super class a DataFormat class and simply add your method.


Need Your Help

create web part that looks like out-of-the box sharepoint list

sharepoint sharepoint-2010

I have to create a web part that displays all site collections under the root site. The requirements are:

Naming and referring to a chart in VBA

vba excel-vba excel-2010

I am trying to create charts in excel using VBA . The code is as follows :

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.