Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

android date format


    private fun setDateFormat() {
        val c = Calendar.getInstance()

        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.time)

        val sdfDate = SimpleDateFormat("yyyy-MMM-dd").format(c.time)
        //(yyyy-MMM-dd -> 2022-Jan-14), (yyyy-MM-dd -> 2022-01-14), (yyyy-MMMM-dd -> 2022-January-14)

        val sdfTime24 = SimpleDateFormat("HH:mm:ss aa").format(c.time)

        val sdfTimeAm = SimpleDateFormat("hh:mm aa").format(c.time)

        Log.d("Date",
            "
 sdf : $sdf" +
                    "
 sdfDate : $sdfDate" +
                    "
 sdfTime24 : $sdfTime24" +
                    "
 sdfTimeAm : $sdfTimeAm")

        /*
        * Outut
        * sdf : 2022-01-14 21:09:54
        * sdfDate : 2022-Jan-14
        * sdfTime24 : 21:09:54 pm
        * sdfTimeAm : 09:09 pm
        */

    }
Source by developer.android.com #
 
PREVIOUS NEXT
Tagged: #android #date #format
ADD COMMENT
Topic
Name
3+9 =