A blog for technology, SEO tips, website development and open source programming.

Display formatted date/time using String.format()

0 641

Examples of using String.format() to display formatted calendar

package com.panayiotisgeorgiou.androidtime;

import java.util.Calendar;

import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {

protected void onCreate(Bundle savedInstanceState) {

TextView cal = (TextView)findViewById(R.id.cal);

Calendar calendar = Calendar.getInstance();

String.format(“%td-%tm-%tYn”, calendar, calendar, calendar) +
String.format(“%ty/%tm/%tdn”, calendar, calendar, calendar) +
String.format(“%tI:%tM:%tS %tpn”, calendar, calendar, calendar, calendar) +
“n” +
String.format(“%tDn”, calendar) +
String.format(“%tcn”, calendar) +
String.format(“%tFn”, calendar) +
String.format(“%trn”, calendar)


Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More