Example usage for java.text DateFormat parse

List of usage examples for java.text DateFormat parse

Introduction

In this page you can find the example usage for java.text DateFormat parse.

Prototype

public Date parse(String source) throws ParseException 

Source Link

Document

Parses text from the beginning of the given string to produce a date.

Usage

From source file:Main.java

public static void main(String[] args) {

    String str = "Thu Jun 06 2013 00:00:00 GMT+0530";
    DateFormat outputDate = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss");
    try {//from  w w w  .j  av  a 2 s . c o m
        Date date = outputDate.parse(str);
        String date1 = new SimpleDateFormat("dd-mm-yyyy, hh:mm:ss").format(date);
        System.out.println(date1.toString());
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Date birth = null;//from   w  ww.j a  v  a2 s .c  o m
    String birthDate = "30-MAR-2012";
    DateFormat formatter = null;
    formatter = new SimpleDateFormat("dd-MMM-yyyy");
    birth = (Date) formatter.parse(birthDate); // birtDate is a string
    if (birth == null) {
        System.out.println("Birth object is still null.");
    } else {
        System.out.println("Default date format " + birth);
        System.out.println("Our SimpleDateFormat " + formatter.format(birth));
        System.out.println("Our SimpleDateFormat with all uppercase " + formatter.format(birth).toUpperCase());
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String input = "Thu Jun 06 2015 00:00:00 GMT+0530 (India Standard Time)";
    DateFormat inputFormat = new SimpleDateFormat("E MMM dd yyyy HH:mm:ss 'GMT'z", Locale.ENGLISH);
    Date date = inputFormat.parse(input);

    DateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH);
    outputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    String output = outputFormat.format(date);
    System.out.println(output);//from  w  ww . j a  va 2 s  .c  o  m
}

From source file:DateTest.java

public static void main(String[] args) throws ParseException {
    DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT);
    formatter.setLenient(false);/*from w w w . ja  v  a  2  s  .  c o m*/
    Date theDate = formatter.parse(args[0]);
    System.out.println(theDate);
}

From source file:Main.java

public static void main(String[] args) {

    String str_date = "2015-05-15 05:55:55.0";
    DateFormat formatter;
    Date date;//from w w w  . ja v  a2 s . c  o  m
    try {
        formatter = new SimpleDateFormat("yyyy-MM-d HH:mm:ss");
        date = formatter.parse(str_date);
        System.out.println(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*w  ww  .j  a  v a2 s  .c o  m*/
        String str_date = "Sat Sep 8 10:13:09 GMT+0530 2012";
        DateFormat formatter;
        Date date;
        formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss 'GMT'z yyyy");
        date = (Date) formatter.parse(str_date);
        System.out.println("Today is " + date);
    } catch (ParseException e) {
        System.out.println("Exception :" + e);
    }
}

From source file:eu.optimis.infrastructureproviderriskassessmenttool.core.riskmonitoring.MonClientCommandline.java

public static void main(String[] args) {

    //PropertyConfigurator.configure(ConfigManager.getConfigFilePath(ConfigManager.LOG4J_CONFIG_FILE));
    log.info("IPRA: Test Monitoring Client...");
    PropertiesConfiguration configOptimis = ConfigManager
            .getPropertiesConfiguration(ConfigManager.OPTIMIS_CONFIG_FILE);

    // Test Monitoring Access
    getClient mclient = new getClient(configOptimis.getString("optimis-ipvm"),
            Integer.parseInt(configOptimis.getString("monitoringport")),
            configOptimis.getString("monitoringpath"));
    /*  /*from   w w  w  .jav  a  2 s. c  o  m*/
      CloudOptimizerRESTClient CoClient = new CloudOptimizerRESTClient(rb.getString("config.coservicehost"), Integer.parseInt(rb.getString("config.coserviceport")), "CloudOptimizer");
              
     System.out.println(CoClient.getNodesId().get(0));
     System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
     System.out.println(CoClient.getPhysicalResource("optimis1"));
     System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
     System.out.println(CoClient.getVMsIdsOfService("DemoApp"));
     System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
              
    */
    MonitoringResourceDatasets mrd = null;
    /*
    mrd = mclient.getReportForAllPhysical();
    MonPrinter(mrd);
            
    mrd = mclient.getReportForAllVirtual();
    MonPrinter(mrd);
    */
    //mrd = mclient.getLatestReportForPhysical("optimis1");
    //mrd = mclient.getLatestReportForMetricName("free_memory","physical");
    //mrd = mclient.getReportForService("DemoApp");
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    Date start = null;
    try {
        start = df.parse("01/01/2010");
    } catch (ParseException e) {
        e.printStackTrace();
    }

    Date end = new Date();

    //mrd = mclient.getReportForPartMetricName("status", "physical", start, end);
    //MonPrinter(mrd);
    mrd = mclient.getReportForPartMetricName("vm_state", "virtual", start, end);
    MonPrinter(mrd);
}

From source file:MainGeneratePicasaIniFile.java

public static void main(String[] args) {
    try {//from  w  w  w .ja v  a  2s.co m

        Calendar start = Calendar.getInstance();

        start.set(1899, 11, 30, 0, 0);

        PicasawebService myService = new PicasawebService("My Application");
        myService.setUserCredentials(args[0], args[1]);

        // Get a list of all entries
        URL metafeedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/" + args[0] + "?kind=album");
        System.out.println("Getting Picasa Web Albums entries...\n");
        UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class);

        // resultFeed.

        File root = new File(args[2]);
        File[] albuns = root.listFiles();

        int j = 0;
        List<GphotoEntry> entries = resultFeed.getEntries();
        for (int i = 0; i < entries.size(); i++) {
            GphotoEntry entry = entries.get(i);
            String href = entry.getHtmlLink().getHref();

            String name = entry.getTitle().getPlainText();

            for (File album : albuns) {
                if (album.getName().equals(name) && !href.contains("02?")) {
                    File picasaini = new File(album, "Picasa.ini");

                    if (!picasaini.exists()) {
                        StringBuilder builder = new StringBuilder();

                        builder.append("\n");
                        builder.append("[Picasa]\n");
                        builder.append("name=");
                        builder.append(name);
                        builder.append("\n");
                        builder.append("location=");
                        Collection<Extension> extensions = entry.getExtensions();

                        for (Extension extension : extensions) {

                            if (extension instanceof GphotoLocation) {
                                GphotoLocation location = (GphotoLocation) extension;
                                if (location.getValue() != null) {
                                    builder.append(location.getValue());
                                }
                            }
                        }
                        builder.append("\n");
                        builder.append("category=Folders on Disk");
                        builder.append("\n");
                        builder.append("date=");
                        String source = name.substring(0, 10);

                        DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");

                        Date date = formater.parse(source);

                        Calendar end = Calendar.getInstance();

                        end.setTime(date);

                        builder.append(daysBetween(start, end));
                        builder.append(".000000");
                        builder.append("\n");
                        builder.append(args[0]);
                        builder.append("_lh=");
                        builder.append(entry.getGphotoId());
                        builder.append("\n");
                        builder.append("P2category=Folders on Disk");
                        builder.append("\n");

                        URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/" + args[0]
                                + "/albumid/" + entry.getGphotoId());

                        AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class);

                        for (GphotoEntry photo : feed.getEntries()) {
                            builder.append("\n");
                            builder.append("[");
                            builder.append(photo.getTitle().getPlainText());
                            builder.append("]");
                            builder.append("\n");
                            long id = Long.parseLong(photo.getGphotoId());

                            builder.append("IIDLIST_");
                            builder.append(args[0]);
                            builder.append("_lh=");
                            builder.append(Long.toHexString(id));
                            builder.append("\n");
                        }

                        System.out.println(builder.toString());
                        IOUtils.write(builder.toString(), new FileOutputStream(picasaini));
                        j++;
                    }
                }

            }

        }
        System.out.println(j);
        System.out.println("\nTotal Entries: " + entries.size());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.joymove.service.impl.JOYUserServiceImpl.java

public static void main(String[] args) throws Exception {

    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:test.xml");
    Map<String, Object> likeCondition = new HashMap<String, Object>();
    JOYUser user = new JOYUser();
    DateFormat formatWithTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    user.registerTime = formatWithTime.parse("2013-04-29 15:08:41");

    JOYUserDao dao = (JOYUserDao) context.getBean("JOYUserDao");
    likeCondition.putAll(user.toMap());/* w  ww  . j  a  v a 2 s  . co m*/
    likeCondition.put("filter", user);
    List<Map<String, Object>> mapList = dao.getPagedRecordList(likeCondition);
    for (int i = 0; i < mapList.size(); i++) {
        JOYUser userObj = new JOYUser();
        user.fromMap(mapList.get(i));
        System.out.println(user);
    }

    /*
            
            
    JOYPayHistoryService service = (JOYPayHistoryService)context.getBean("JOYPayHistoryService");
    JOYPayHistory payHistoryNew = new JOYPayHistory();
    payHistoryNew.balance = 0.2;
    payHistoryNew.type = 2;
    service.deleteByProperties(payHistoryNew);
            
            
    /*
    JOYUserService service = (JOYUserService)context.getBean("JOYUserService");
    JOYUser user = new JOYUser();
    user.mobileNo = "18500217642";
    List<Map<String,Object>> mapList = service.getExtendInfoPagedList(" select u.*, m.driverLicenseNumber  from JOY_Users u left join JOY_DriverLicense m on u.mobileNo = m.mobileNo ",user);
            
            
    //   JOYUser user2 = new JOYUser();
    Map<String,Object> t = mapList.get(0);
    Iterator i =t.entrySet().iterator();
    JSONObject tt = new JSONObject();
    while(i.hasNext()) {
            
       Map.Entry<String,Object> haha = (Map.Entry<String,Object>)i.next();
        if(String.valueOf(haha.getValue()).equals("null")) {
    logger.trace(haha.getKey()+" is null");
       }
    }
            
    /*
    user2.username = "?";
    user.mobileNo="18500217642";
    service.updateRecord(user2,user);
    user = service.getNeededRecord(user);
      logger.trace(user);
            
    /*
    JOYOrderService service = (JOYOrderService) context.getBean("JOYOrderService");
    JOYOrder order = new JOYOrder();
    order = service.getNeededRecord(order);
    JOYOrder order2 = new JOYOrder();
    order2.startTime = order.startTime;
    order = new JOYOrder();
    order.startTime = new Date(System.currentTimeMillis());
    service.updateRecord(order,order2);
       /*
    JOYNReserveOrderService  service  = (JOYNReserveOrderService)context.getBean("JOYNReserveOrderService");
    JOYReserveOrder order = new JOYReserveOrder();
    //service.insertRecord(order);
    JOYReserveOrder order2 = new JOYReserveOrder();
    order2.mobileNo = "18500217642";
    order2.startTime = new Date(System.currentTimeMillis());
      service.insertRecord(order2);
    order2.startTime = null;
    order = service.getNeededRecord(order2);
     order.startTime = new Date(System.currentTimeMillis());
    service.updateRecord(order,order2);
      order2.startTime = order.startTime;
    order2.mobileNo = null;
    order = service.getNeededRecord(order2);
    logger.trace(order);
    /*
    order.delFlag = 1;
    order.startTime = new Date(System.currentTimeMillis()+30);
    service.updateRecord(order,order2);
            
    order2.mobileNo = null;
    order2.startTime = order.startTime;
    order = service.getNeededRecord(order2);
    logger.trace(order);
    //service.deleteByProperties(order);
            
            
    /*
    JOYIdAuthInfoService service  = (JOYIdAuthInfoService)context.getBean("JOYIdAuthInfoService");
    JOYIdAuthInfo dl = new JOYIdAuthInfo();
    dl.idAuthInfo = "nihao".getBytes();
    dl.idAuthInfo_back = "Hello world".getBytes();
    JOYIdAuthInfo dl2 = new JOYIdAuthInfo();
    dl2.mobileNo = "15577586649";
    service.updateRecord(dl,dl2);
            
            
    service.getNeededList(dl2,null,null);
            
            
            
    List<JOYIdAuthInfo> dList = service.getNeededList(dl,null,null);
    logger.trace(dList.get(0));
            
    for(int i=0;i<dList.get(0).idAuthInfo.length;i++)
    System.out.format("%c",dList.get(0).idAuthInfo[i]);
    /*
    JOYUser user = new JOYUser();
    JOYUser user1 = new JOYUser();
    user.mobileNo = ("18500217642");
    List<JOYUser> userList =  service.getNeededList(user,0,10);
      logger.trace("sdfdsdsf :"+userList.size());
    JOYUser u = userList.get(0);
    logger.trace(u);
     */
}

From source file:MainClass.java

public static void main(String[] args) {
    DateFormat shortDf = DateFormat.getDateInstance(DateFormat.SHORT);

    DateFormat mediumDf = DateFormat.getDateInstance(DateFormat.MEDIUM);
    DateFormat longDf = DateFormat.getDateInstance(DateFormat.LONG);
    DateFormat fullDf = DateFormat.getDateInstance(DateFormat.FULL);
    System.out.println(shortDf.format(new Date()));
    System.out.println(mediumDf.format(new Date()));
    System.out.println(longDf.format(new Date()));
    System.out.println(fullDf.format(new Date()));

    // parsing//w  ww  .j a  v  a 2s . c om
    try {
        Date date = shortDf.parse("Jan 32, 2005");
    } catch (ParseException e) {
    }
}