How do I display the current date and time in the text viewer inside Fragment?


I would like to display current Date and time in a Textview in my app fragments, in the Format : DD/MM/YEAR:H:Min but I have no idea how to code this up as I am new to programming. Where/What to begin with?

my current code :

package com.example.myshops;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class Monday_fragment extends Fragment implements OnClickListener { private TextView datetimetext;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.item1_fragment, container, false);

    Button nextpageButton = (Button) v.findViewById(;
    nextpageButton.setOnClickListener((OnClickListener) getActivity());
    return v;

public void onClick(View v) {
    switch (v.getId()) {


    datetimetext.setText("" + DateFormat.format("dd/MM/yyyy kk:mm", System.currentTimeMillis()));

    //---Inflate the layout for this fragment---
//return inflater.inflate( R.layout.item1_fragment, container, false);



Okay, not that hard as there are several methods to do this.

String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());

// textView is the TextView view that should display it

There is more to read in the documentation that can easily be found here There you'll find more information on how to change the format used for conversion.