DateTimeServer.java 1.37 KB
Newer Older
Luis Gangas committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package trismegistoplanilla.utilities;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import trismegistoplanilla.sqlserverdao.SqlserverDAOFactory;

public class DateTimeServer {

  public static String getDateTimeServer() {
    String datetime = "";
    String base = "planillabd";
    String sql = "select format(getdate(), 'dd/MM/yyyy HH:mm:ss') + ' ' + right(convert(varchar, getdate(), 0), 2) fechaServer";
18
    
Luis Gangas committed
19 20 21 22 23 24 25 26 27
    Connection conexion = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
      conexion = SqlserverDAOFactory.obtenerConexion(base);
      ps = conexion.prepareStatement(sql);
      rs = ps.executeQuery();
      rs.next();
      datetime = rs.getString("fechaServer");
28
    } catch (SQLException e) {      
Luis Gangas committed
29 30 31 32 33 34 35 36 37 38 39 40
    } finally {
      try {
        if (rs != null) {
          rs.close();
        }
        if (ps != null) {
          ps.close();
        }
        if (conexion != null) {
          conexion.close();
        }
      } catch (SQLException e) {
41
        e.printStackTrace();
Luis Gangas committed
42 43 44 45 46 47 48 49 50 51 52
      }
    }
    return datetime;
  }

  public static String getdate() {
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    Date date = new Date();
    return dateFormat.format(date);
  }
}