Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android java date from internet

 private void getDate() {

        RequestQueue queue = Volley.newRequestQueue(getContext());
        String url ="http://worldtimeapi.org/api/timezone/Asia/Kolkata";

        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);

                          // stroting datatime in a string
                            String result = jsonObject.getString("datetime");
                          // extracting date
                            result = result.substring(0, 10);
                          
                         // reformatting to convert it to dd/MM/yyyy from yyyy/MM/dd
                            String internetDate = result.substring(8, 10) + "-" + result.substring(5, 7) + "-" + result.substring(0, 4);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                noElection.setText(error.getMessage());
                noElection.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.GONE);
            }
        });
        queue.add(stringRequest);
    }
Comment

PREVIOUS NEXT
Code Example
Java :: java take out cn from dn 
Java :: java swing jtable different color each row 
Java :: java swing absolute position 
Java :: java remove from arraylist while iterating 
Java :: get all number from string java 
Java :: how to navigate to last back stack in android studio 
Java :: entryset in java loop 
Java :: big integer input in java 
Java :: how to byheart faster 
Java :: Date from String java7 
Java :: how to compare 3 numbers in java 
Java :: how to stop timer in java 
Java :: java trim method 
Java :: how to refresh activity without intent in android 
Java :: java random Double between 
Java :: Duplicate class org.intellij.lang.annotations. 
Java :: how to add java_home in mac 
Java :: android studio get string from strings.xml 
Java :: play sound on button click android studio 
Java :: how to declare list of object in java as constant 
Java :: java check if divisible 
Java :: create embeds jda discord 
Java :: change java version maven 
Java :: hibernate select count 
Java :: install java 8 arch 
Java :: mockito verify not called 
Java :: open camera in android 
Java :: java system.out.print two dimensional array 
Java :: spring boot mongodb update subdocument 
Java :: rjava error 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =