Example usage for java.util Date Date

List of usage examples for java.util Date Date

Introduction

In this page you can find the example usage for java.util Date Date.

Prototype

public Date() 

Source Link

Document

Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    String host = "host";
    int port = 25;
    String from = "from@from.net";
    String toAddr = "to@to.net";

    Socket servSocket = new Socket(host, port);
    DataOutputStream os = new DataOutputStream(servSocket.getOutputStream());
    DataInputStream is = new DataInputStream(servSocket.getInputStream());

    if (servSocket != null && os != null && is != null) {
        os.writeBytes("HELO\r\n");
        os.writeBytes("MAIL From:" + from + " \r\n");
        os.writeBytes("RCPT To:" + toAddr + "\r\n");
        os.writeBytes("DATA\r\n");
        os.writeBytes("X-Mailer: Java\r\n");
        os.writeBytes(/*  w  w  w .ja v a 2 s  .c om*/
                "DATE: " + DateFormat.getDateInstance(DateFormat.FULL, Locale.US).format(new Date()) + "\r\n");
        os.writeBytes("From:" + from + "\r\n");
        os.writeBytes("To:" + toAddr + "\r\n");
    }

    os.writeBytes("Subject:\r\n");
    os.writeBytes("body\r\n");
    os.writeBytes("\r\n.\r\n");
    os.writeBytes("QUIT\r\n");
    String responseline;
    while ((responseline = is.readUTF()) != null) {
        if (responseline.indexOf("Ok") != -1)
            break;
    }
}

From source file:MainClass.java

public static void main(String[] pArgs) throws Exception {
    Date now = new Date();
    System.out.println("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
    Iterator iter = DateUtils.iterator(now, DateUtils.RANGE_WEEK_SUNDAY);
    while (iter.hasNext()) {
        Calendar cal = (Calendar) iter.next();
        Date cur = cal.getTime();
        System.out.println("iterate: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(cur));
    }//from   www  .ja  v a  2  s  .c  om
}

From source file:com.kookoo.outbound.OutboundTest.java

public static void main(String a[]) {
    try {//  w  ww  .  jav  a 2s .c o m
        String server_ip = "http://XXXX:8080"; /*change to your web server*/
        String phone_no1 = "09985XXXXX";/*change number to your numbers*/
        String phone_no2 = "09985XXXXX";/*change number to your numbers*/
        String api_key = "KKXXXXX";/*kookoo api key*/
        String kookoo_number = "91xxxxx";/*kookoo assigned number*/

        Date d = new Date();
        String trackId = "" + d.getTime();
        String url = "http://kookoo.in/outbound/outbound.php";
        URIBuilder uribuilder = new URIBuilder(url);
        uribuilder.addParameter("api_key", api_key);
        uribuilder.addParameter("phone_no", phone_no1);
        uribuilder.addParameter("caller_id", kookoo_number);
        /*assigned kookoo number*/
        uribuilder.addParameter("url",
                server_ip + "/kookoocall/outboundcall?number2=" + phone_no2 + "&trackId=" + trackId);
        uribuilder.addParameter("callback_url",
                server_ip + "/kookoocall/outbound_callstatus?number2=" + phone_no2 + "&trackId=" + trackId);

        URI uri = uribuilder.build();
        System.out.println("Final Outboud API url " + uri);
        HttpGet request = new HttpGet(uri);
        HttpClient client = HttpClientBuilder.create().build();
        HttpResponse response = client.execute(request);

        String responseString = new BasicResponseHandler().handleResponse(response);
        System.out.println(responseString);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:co.id.ipb.ilkom.training.db.CustomerServiceJpaExample.java

public static void main(String[] args) {
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            SpringDataJpaConfiguration.class);
    CustomerService customerService = applicationContext.getBean(CustomerService.class);
    Customer customer = new Customer();
    customer.setId(10);/*from  w  ww.ja  v  a  2s. c om*/
    customer.setName("Fulan");
    customer.setEmail("fulan@email.com");
    customer.setAddress("kampus IPB");
    customer.setBirthDate(new Date());
    customerService.saveOrUpdate(customer);
}

From source file:Main.java

public static void main(String[] args) {
    String[] newMonths = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };
    String[] newShortMonths = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov",
            "dec" };
    String[] newWeekdays = { "", "Monday", "Tuesday", "Webnesday", "Thursday", "Friday", "Saturaday",
            "Sunday" };
    String[] shortWeekdays = { "", "monday", "tuesday", "webnesday", "thursday", "friday", "saturaday",
            "sunday" };

    DateFormatSymbols symbols = new DateFormatSymbols();
    symbols.setMonths(newMonths);//  w w w  .j ava2 s. co m
    symbols.setShortMonths(newShortMonths);
    symbols.setWeekdays(newWeekdays);
    symbols.setShortWeekdays(shortWeekdays);

    DateFormat format = new SimpleDateFormat("dd MMMM yyyy", symbols);
    System.out.println(format.format(new Date()));

    format = new SimpleDateFormat("dd MMM yyyy", symbols);
    System.out.println(format.format(new Date()));

    format = new SimpleDateFormat("EEEE, dd MMM yyyy", symbols);
    System.out.println(format.format(new Date()));

    format = new SimpleDateFormat("E, dd MMM yyyy", symbols);
    System.out.println(format.format(new Date()));
}

From source file:ar.com.springbasic.app.MainApp.java

public static void main(String[] args) {

    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("newSpringXMLConfig.xml");

    AdminDao adminDao = (AdminDao) applicationContext.getBean("adminDao");

    Timestamp ts = new Timestamp(new Date().getTime());

    //        ***Creo un nuevo admin***
    //          Admin admin = new Admin();
    //        admin.setCargo("Gerente");
    //        admin.setNombre("carlo");
    //        admin.setFechaCreacion(ts);

    try {/*from  ww  w .ja  va  2  s .c om*/
        //            ***Guardo el admin***
        //            adminDao.save(admin);

        //               ***traigo todos los campos ***
        //            List<Admin> admins = adminDao.findAll();
        //            for (Object admin1 : admins) {
        //                System.out.println(admin1);    
        //            }

        //            ***Busco por un id***
        //            System.out.println(adminDao.findById(2));

        //            Busco por un nombre
        //            System.out.println(adminDao.findByNombre("pepe").toString());

        //            Modificar y borrar
        //            Admin admin = adminDao.findById(1);
        //            System.out.println("Admin con id 1= " + admin);
        //            
        //            admin.setCargo("Subgerente");
        //            admin.setNombre("Adrian");
        //            
        //            if (adminDao.update(admin)) {
        //                System.out.println("Actializacion correcta " +admin);
        //            }
        //            if (adminDao.delete(admin.getIdAd())) {
        //                System.out.println("Admin: "+admin.getNombre() +" eliminado correctamente");
        //                
        //            }

        List<Admin> admins = new ArrayList<>();
        admins.add(new Admin("Papulo", "Jefe de ingenieria", ts));
        admins.add(new Admin("Cucuro", "Chorro", ts));
        admins.add(new Admin("Zafalo", "Mujeriego", ts));
        admins.add(new Admin("Mengano", "Chupa culo", ts));

        int[] vals = adminDao.saveAll(admins);

        for (int val : vals) {
            System.out.println("Filas afectadas para esta operacion= " + val);
        }

    } catch (CannotGetJdbcConnectionException e) {
        //Error de conneccion
        System.out.println(e);
    } catch (DataAccessException b) {
        //Error de acceso a datos
        System.out.println(b);

    }

}

From source file:MainClass.java

public static void main(String[] pArgs) throws Exception {
    Date now = new Date();
    System.out.println(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));

}

From source file:FormattedSample.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Formatted Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd");
    DateFormatter displayFormatter = new DateFormatter(displayFormat);
    DateFormat editFormat = new SimpleDateFormat("MM/dd/yy");
    DateFormatter editFormatter = new DateFormatter(editFormat);
    DefaultFormatterFactory factory = new DefaultFormatterFactory(displayFormatter, displayFormatter,
            editFormatter);//www .j  a v  a 2s.  co m
    JFormattedTextField date2TextField = new JFormattedTextField(factory, new Date());
    frame.add(date2TextField, BorderLayout.NORTH);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JFormattedTextField source = (JFormattedTextField) actionEvent.getSource();
            Object value = source.getValue();
            System.out.println("Class: " + value.getClass());
            System.out.println("Value: " + value);
        }
    };
    date2TextField.addActionListener(actionListener);

    frame.add(new JTextField(), BorderLayout.SOUTH);
    frame.setSize(250, 100);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Formatted Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd");
    DateFormatter displayFormatter = new DateFormatter(displayFormat);
    DateFormat editFormat = new SimpleDateFormat("MM/dd/yy");
    DateFormatter editFormatter = new DateFormatter(editFormat);
    DefaultFormatterFactory factory = new DefaultFormatterFactory(displayFormatter, displayFormatter,
            editFormatter);//from w  w  w .  j  a v  a  2  s.  co m
    JFormattedTextField date2TextField = new JFormattedTextField(factory, new Date());
    frame.add(date2TextField, BorderLayout.NORTH);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JFormattedTextField source = (JFormattedTextField) actionEvent.getSource();
            Object value = source.getValue();
            System.out.println("Class: " + value.getClass());
            System.out.println("Value: " + value);
        }
    };
    date2TextField.addActionListener(actionListener);
    frame.add(new JTextField(), BorderLayout.SOUTH);

    frame.setSize(250, 100);
    frame.setVisible(true);
}

From source file:com.cjwagner.InfoSecPriv.ExtensionServer.java

public static void main(String[] args) {
    initializeLogStore();/*from  w  w w .j a v  a2s.c o  m*/

    get("/data", (request, response) -> {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.MINUTE, -5);
        Date tMinusDelta = cal.getTime();

        Map<String, LoggerMessage> filtered = new HashMap<String, LoggerMessage>();
        for (Map.Entry<String, LoggerMessage> entry : logStore.entrySet()) {
            String ip = entry.getKey();
            LoggerMessage logmess = entry.getValue();
            LoggerMessage logmessFiltered = new LoggerMessage();
            logmessFiltered.setFirstLogTime(logmess.getFirstLogTime());
            List<LogData> filteredData = new ArrayList<LogData>();
            logmessFiltered.setLogs(filteredData);
            for (LogData data : logmess.getLogs()) {
                if (data.getDate().after(tMinusDelta)) {
                    filteredData.add(data);
                }
            }

            filtered.put(ip, logmessFiltered);
        }

        ObjectMapper objMapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true);
        String jsonResponse = objMapper.writeValueAsString(filtered);
        System.out.println("Responded to query for recent data from IP: " + request.ip());
        return jsonResponse;
    });

    post("/LicenseRegistry", (request, response) -> {
        if (storeSize >= MAXSTORESIZE) {
            response.status(507);//insufficient storage
            return "Server storage full!";
        }

        String ip = request.ip().replace(':', '_');
        String json = request.body();

        try {
            LoggerMessage logMess = LoggerMessage.fromJSON(json);
            logMess.setFirstLogTime(new Date());
            LoggerMessage rec = logStore.get(ip);
            if (rec == null) {
                logStore.put(ip, logMess);
                rec = logMess;
            } else {
                rec.getLogs().addAll(logMess.getLogs());
            }
            updateLogFile(ip, rec);
            storeSize += logMess.getLogs().size();
            response.status(200);

            System.out.println("Recieved log data from IP: " + ip);
            return "LicenseKey:<c706cfe7-b748-4d75-98b5-c6b32ab789cb>";
        } catch (JsonParseException jpe) {
            response.status(HTTP_BAD_REQUEST);
            System.out.println("Failed to parse log data from IP: " + ip);
            return jpe.getMessage();
        }
    });
}