Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

EAP DE INGENIERIA DE SISTEMAS E INFORMATICA

TALLER DE DISEÑO DE SOLUCIONES MÓVILES


Android Studio
Docentes: PAZ PURISACA ROLANDO

Laboratorio:13 TEMA: FECHA Y TIEMPO

Actividad 1:
Mostrar la fecha del sistema
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#03A9F4"
tools:context=".MainActivity">

<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#000000"
tools:layout_editor_absoluteX="104dp"
tools:layout_editor_absoluteY="71dp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv1"
android:onClick="calcular"
android:text="Ver Fecha" />

</RelativeLayout>

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class MainActivity extends AppCompatActivity {


public TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1=(TextView) findViewById(R.id.tv1);
}
public void calcular(View view){
String cadena;
Date fecha;
fecha=new Date();
DateFormat formatoFecha=new SimpleDateFormat("dd/MM/yyyy");
cadena=formatoFecha.format(fecha);
tv1.setText("Fecha = "+cadena);
}
}

Actividad 2:
Mostrar la hora del sistema
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFC107"
tools:context=".MainActivity2">

<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#000000" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv2"
android:onClick="calcularH"
android:text="Ver Hora" />
</RelativeLayout>

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class MainActivity2 extends AppCompatActivity {


public TextView tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
tv2=(TextView) findViewById(R.id.tv2);
}
public void calcularH(View view){
String cadena;
Date hora;
hora=new Date();
DateFormat formatohora=new SimpleDateFormat("h:m:s");
formatohora.setTimeZone(TimeZone.getTimeZone("America/Lima"));
cadena=formatohora.format(hora);
tv2.setText("Hora = "+cadena);
}
}

Actividad 3:
Mostrar el nombre del mes
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C1ED8E"
tools:context=".MainActivity3">

<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#000000" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv3"
android:onClick="calcularM"
android:text="Button" />
</RelativeLayout>

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class MainActivity3 extends AppCompatActivity {


public TextView tv3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
tv3=(TextView) findViewById(R.id.tv3);
}
public void calcularM(View view){
String cadena;
Date fecha;
fecha=new Date();
DateFormat formatoFecha=new SimpleDateFormat("MMMM");
cadena=formatoFecha.format(fecha);
tv3.setText("El mes es = "+cadena);
}
}

Actividad 4:
Mostrar un calendario y seleccionar un día.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FAE6FD"
tools:context=".MainActivity4">

<TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#000000" />

<CalendarView
android:id="@+id/cal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv4"
android:background="#FFFAD1" />
</RelativeLayout>

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class MainActivity4 extends AppCompatActivity {
public TextView tv4;
public CalendarView cal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
tv4=(TextView) findViewById(R.id.tv4);
cal=(CalendarView) findViewById(R.id.cal);
cal.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
{
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth)
month=month+1;
tv4.setText("Fecha seleccionada: "+dayOfMonth+"/"+month+"/"+year);
}
});
}
}

You might also like