Exchange

How To Split Date Format as Date, Month, Year in Android Studio

In Android Studio, you can split a date format into date, month, and year by using the SimpleDateFormat class. Here's an example code snippet:

public class MainActivity extends AppCompatActivity {

private Calendar calendar;
private String date;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

calendar = Calendar.getInstance();
date = DateFormat.getDateInstance().format(calendar.getTime());


String[] items1 = date.split(" ");
String d1=items1[0];
String m1=items1[1];
String y1=items1[2];

Toast.makeText(this, y1 + m1 + d1, Toast.LENGTH_LONG).show();

}
}
Android Studio
android studio tutorials



Post a Comment

0 Comments