0

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.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.Fragment;
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;

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

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

    Button nextpageButton = (Button) v.findViewById(R.id.Item2Button);
    nextpageButton.setOnClickListener((OnClickListener) getActivity());
    return v;
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.nextpageButton:



        break;
    }





    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);



}



}
user3514625
  • 21
  • 2
  • 5

2 Answers2

0

Use

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

it should work

try to change your code to this

@Override
public void onClick(View v) {

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

    switch (v.getId()) {    
    case R.id.nextpageButton:
        break;
    }
}
Boe-Dev
  • 1,585
  • 2
  • 14
  • 26
0

try this

new SimpleDateFormat("dd/MM/yyyy HH:mm").format(System.currentTimeMillis() * 1000L);
maddy d
  • 1,530
  • 2
  • 12
  • 23