How to convert the format of the date and time consulted from the Internet?

0

As you can see in the image below, I check the date and time from the Internet, everything goes well even with the time zone, the problem is that the name of Month and Day < /> of the week come in English, how could I change them to Spanish and delete that data that says "GMT-0500" .

Here is the code that performs the query of the date and time:

public void GetTime(){
        try {
            TimeTCPClient client = new TimeTCPClient();
            try {
                // Set timeout of 60 seconds
                client.setDefaultTimeout(60000);
                // Connecting to time server
                // Other time servers can be found at : http://tf.nist.gov/tf-cgi/servers.cgi#
                // Make sure that your program NEVER queries a server more frequently than once every 4 seconds
                client.connect("time.nist.gov");
                //System.out.println(client.getDate());
                Hora.setText("Ultima Actualización el "+client.getDate().toString().trim());
            } finally {
                client.disconnect();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
}

I hope you can help me, or if you know another method I would also appreciate it. Thanks!

    
asked by Rosyec Parrado 12.04.2018 в 02:15
source

1 answer

2

You have to format it with the SimpleDateFormat method, like this:

private String getDate() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE dd MMMM yyyy  HH:mm:ss", Locale.getDefault());
        Date date = new Date();
        return dateFormat.format(date);
    }

Locale.getDefault() gives the values in the language that the device has. The date pattern there are several, examples: EE = mar EEEE = martes d = 1 dd = 01 hh:mm a = 10:10 AM ... More info: link

    
answered by 12.04.2018 / 03:10
source