Ver Mensaje Individual
  #18 (permalink)  
Antiguo 31/05/2005, 16:51
Avatar de stock
stock
 
Fecha de Ingreso: junio-2004
Ubicación: Monterrey NL
Mensajes: 2.390
Antigüedad: 22 años, 4 meses
Puntos: 53
Tema: Fechas
Pregunta: Como obtener la fecha del sistema??
Respuesta: Con la clase Date obtenemos la fecha actual del sistema

Código PHP:
/*
 * Author: Crysfel Villa
 * Created: Thursday, May 26, 2005 7:55:39 PM
 * Modified: Thursday, May 26, 2005 7:55:39 PM
 */
import java.util.*;
import java.text.*;

public class 
Fecha
{
    private 
Date hoy;
    private 
SimpleDateFormat sdf;
    private 
int dia;
    private 
int mes;
    private 
int year;
    
    public 
Fecha(){
        
String fecha = "";
        
hoy = new Date();
        
sdf = new SimpleDateFormat("dd-MM-yyyy");
        
fecha = sdf.format(hoy);
        
dia = Integer.parseInt(fecha.substring(0,2));
        
mes = Integer.parseInt(fecha.substring(3,5));
        
year = Integer.parseInt(fecha.substring(6));
    }
    
    
/* 
    / @return La fecha actual del sistema en formato 01/Enero/2005
    */
    
public String getFecha(){
        return 
dia + "/" + getMes(mes) + "/" + year;
    }
    
    
/* 
    / @return La fecha actual del sistema y la hora en formato 01/Enero/2005 10:35
    */
    
public String getFechaTime(){
        return 
dia + "/" + getMes(mes) + "/" + year + " " + hoy.getHours()+ ":" + hoy.getMinutes();
    }
    
    
/* 
    / @param int mes
    / @return El mes en String
    */
    
private String getMes(int m){
        
String mes="";
        switch(
m){
        case 
1 : mes="Enero"; break;
        case 
2 : mes="Febrero"; break;
        case 
3 : mes="Marzo"; break;
        case 
4 : mes="Abril"; break;
        case 
5 : mes="Mayo"; break;
        case 
6 : mes="Junio"; break;
        case 
7 : mes="Julio"; break;
        case 
8 : mes="Agosto"; break;
        case 
9 : mes="Septiembre"; break;
        case 
10 : mes="Octubre"; break;
        case 
11 : mes="Noviembre"; break;
        case 
12 : mes="Diciembre"; break;
        }
        return 
mes;
    }
}