How come the date displays as 21\/1\/2015 instead of 21/1/2015 in Android after parsing the JSON data?

Currently, I am utilizing the DatePicker functionality in my code and transmitting the value via JSON. The desired format for the value is 21/1/2015 without the extra backslashes. How can I resolve this issue?

DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        // Method implementation here
        myCalendar.set(Calendar.YEAR, year);
        myCalendar.set(Calendar.MONTH, monthOfYear);
        myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        updateLabel();
    }

    private void updateLabel() {
        // Method implementation here

            String myFormat = "dd/MM/yyyy"; 
            SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

            edit_message3.setText(sdf.format(myCalendar.getTime()));

            }

edit_message3.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // Implementation here
                new DatePickerDialog(SignupActivity.this, date, myCalendar
                        .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                        myCalendar.get(Calendar.DAY_OF_MONTH)).show();
            }
        });

String birthday = edit_message3.getText().toString();

Answer №1

birthday = birthday.replace("\/","/");

and then retrieve the updated value of birthday or you can follow these steps..

final Calendar cal = Calendar.getInstance();
    int dayOfMonth=cal.get(Calendar.DATE);
    int monthOfYear=cal.get(Calendar.MONTH);
    int year=cal.get(Calendar.YEAR);



@SuppressLint("NewApi")
    @Override
    @Deprecated
    protected Dialog onCreateDialog(int id) {
        //return new DatePickerDialog(this, datePickerListener, year, month, day);

        return new DatePickerDialog(this, pDateSetListener, year, monthOfYear, dayOfMonth);

    }

    private DatePickerDialog.OnDateSetListener pDateSetListener = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int selectedYear,
                              int selectedMonth, int selectedDay) {
            final Calendar calendar = Calendar.getInstance();
            int currentDay=calendar.get(Calendar.DATE);
            int currentMonth=calendar.get(Calendar.MONTH);
            currentMonth = currentMonth + 1;
            int currentYear=calendar.get(Calendar.YEAR);


                 birthday = selectedDay + "/" + (selectedMonth + 1) + "/"
                        + selectedYear;
Log.i("DOB >>", birthday);

        }
    };



@Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                showDialog(0);
            }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Eliminating a character from the JSON output

Here is the JSON response that will be received: { "status": "success", "data": { "Response": "1", "ErrorNumber": "0", "ErrorDescription": "", "ErrorDisplay": "1", "Transactions": [ { ...

Issue encountered when attempting to delete object using DELETE request

I've recently started working with node.js and I'm attempting to remove an object from a JSON file when making a DELETE request. Despite my efforts, the object isn't being deleted as expected. Here is the code I have written: const express = ...

Comparing the Efficiency of Caching JSON Strings and Java Objects

One of the strategies I use in my web services is caching the result with memcached. I have two options for caching: either cache the resulting JSON or cache the source object. However, when caching the source object, I need to convert it to JSON every t ...

Receiving JSON data in Laravel

Having trouble retrieving JSON data in Laravel using the following methods: In my Controller: public function index(Request $request) { dd(Input::all()); } I also attempted this approach: dd(Request::json()->all()); Unfortunately, neither of th ...

What is the best way to handle parsing a JSON in Java that contains a property that could be either a String or an Object?

My backend is using mongodb and nodejs to create an API. The API server will return the same user object in different formats, for example: // curl http://localhost/users/5382f2949a24ed95b44dc04f { id: "5382f2949a24ed95b44dc04f", "name": "jack", "group": ...

Sending non UTF-8 encoded JSON using Python Requests

When sending data to a web service connected to a MySQL server set up with latin-1 collation for its tables, I encountered an issue. The web service is designed to receive JSON payloads, but it does not encode the data properly to save in the database, res ...

Using the key from a nested CSV file as the primary key in Python

Sorry for the confusing title. I have a csv file with rows structured like this: 1234567, Install X Software on Y Machine, ServiceTicket,"{'id': 47, 'name': 'SERVICE BOARD', '_info': {'board_href': ' ...

Angular2: Retrieve and process a JSON array from an API

I'm currently facing an issue with my service while attempting to fetch a json array from an api and showcase it on the page. I believe there might be an error in my code, but I can't pinpoint exactly where. getAuctions(): Promise<Auction[ ...

Error: Python expected a string or bytes-like objectTypeError

Currently, I am attempting to tally the number of components based on the data from a json file. Outlined below is my current approach: # Function to count the components def get_component_count(data, component_name, locator_name, counter=0): if re.m ...

Instructions on implementing getJSON in this code

I recently set up a chained select box with JSON data to populate options, using this Fiddle. While the data is hardcoded for now, I am looking to load it using the $.getJSON() method. However, despite my efforts, I haven't been able to get the code r ...

I keep encountering the following error message: " ERROR Error Code: 200 Message: Http failure during parsing for http://localhost:3000/login"

My Angular Login component is responsible for passing form data to the OnSubmit method. The goal is to send form data from the front-end application and authenticate users based on matching usernames and passwords in a MySQL database. ***This login form i ...

Ionic retrieves a filtered array of JSON data

Having difficulty filtering the array to retrieve values where the parent id matches the id that is provided. For instance, if an ID of 1 is sent, it should result in a new array with 3 items. An ID of 4 will return 1 item, and an ID of 5 will also return ...

iOS AFNetworking post request generates an error: Request failed due to a bad request (400)

When I use AFNetworking to make a post web service call, I consistently receive the following response: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" Below is my code snippet: NSURLSessionConfig ...

Is JSON utilized to execute the necessary JavaScript code?

Is there a way to make an ajax call that returns JavaScript code which can be executed? Can JSON be used for this purpose? ...

Having trouble interpreting JSON attribute "null"

I encountered a problem while attempting to parse a JSON "null" property. Can someone help me understand what the issue might be? The JSON I used was as follows: { "properties" : { "null" : { "value" : false } } } I validated th ...

There appears to be an issue with the JSON format on the CouchDB bulk document API,

I'm currently working on a node console application where I am encountering an issue when trying to post multiple records to the bulk document API on a local CouchDB instance. The error message states that the JSON being sent is "Invalid UTF-8 JSON." ...

Having Difficulty Converting JavaScript Objects/JSON into PHP Arrays

This particular inquiry has no relation to the previously mentioned identical answer/question... In JavaScript, I am dealing with a substantial list of over 1,000 items displayed in this format... var plugins = [ { name: "Roundabout - Interac ...

What could be causing the select2 to not display the most up-to-date information in the control?

I have implemented a progressive search feature but it seems that the data returned is not populating the control properly. $("#selUser").select2({ ajax: { url: "/M01EngineeringData/GetFunctionalLocations", ty ...

Managing various swipe interactions using HTML and JavaScript/jQuery

I'm in the process of creating a mobile multiplayer game using HTML5 and Javascript. The jQuery Plugin "touchwipe" is utilized to manage swipe events in various divs like this: $('#play1').touchwipe({ wipeLeft: function(){ if ...

Is there a way to transform JSON into a CSV file using Python?

Is there a way to convert the logs in the JSON format shown below into a CSV file using Python? JSON Input (log.json): {"time":"14472","abc":"0","Def":[{"name":"C","value":77},{"name":"N","value":88}]} {"time":"1447","abc":"1","Def":[{"name":"C","valu ...