Example usage for java.text SimpleDateFormat parse

List of usage examples for java.text SimpleDateFormat parse

Introduction

In this page you can find the example usage for java.text SimpleDateFormat 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) throws Exception {
    SimpleDateFormat sd = new SimpleDateFormat();
    String dateString = "2015-01-02 14:59:27.953";
    sd.applyPattern("yyyy-MM-dd HH:mm:ss.SSS");
    Date date = sd.parse(dateString);
    sd.applyPattern("MM/dd/yyyy HH:mm a");
    System.out.println(sd.format(date));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String trouble = "18?11?2003";
    String goodOne = "18-11-2003";
    Date date = simpleDateFormat.parse(goodOne);
    System.out.println(date);//from  www . j  a v  a2  s.c o m
    date = simpleDateFormat.parse(trouble);
    System.out.println(date);
    System.out.println(String.format("\\u%04x", (int) trouble.charAt(2)));
    System.out.println(String.format("\\u%04x", (int) goodOne.charAt(2)));

}

From source file:com.clican.pluto.dataprocess.dpl.function.impl.Duration.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    System.out.println(duration(sdf.parse("20070630"), sdf.parse("20070101"), true));
    System.out.println(duration(sdf.parse("20071231"), sdf.parse("20070701"), true));
    System.out.println(duration(sdf.parse("20071231"), sdf.parse("20070101"), true));
    System.out.println(duration(sdf.parse("20080630"), sdf.parse("20080101"), true));
    System.out.println(duration(sdf.parse("20081231"), sdf.parse("20080701"), true));
    System.out.println(duration(sdf.parse("20081231"), sdf.parse("20080101"), true));
    System.out.println(duration(sdf.parse("20090630"), sdf.parse("20090101"), true));
    System.out.println(duration(sdf.parse("20091231"), sdf.parse("20090701"), true));
    System.out.println(duration(sdf.parse("20091231"), sdf.parse("20090101"), true));
}

From source file:Main.java

License:asdf

public static void main(String[] args) {
    String[] tests = { "01/23/1983", "1/23/1983", "asdf/3/2" };

    String formatString = "MM/dd/yyyy";

    SimpleDateFormat sdf = new SimpleDateFormat(formatString);

    for (String test : tests) {
        Date date = null;/*from   w w w. j  a va 2 s . com*/
        try {
            date = sdf.parse(test);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(date);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
    String date = "2003/01/10";
    java.util.Date utilDate = null;
    try {//from   w  ww  .  j a  v a  2s .  c  o  m
        utilDate = formatter.parse(date);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("date:" + date);
    System.out.println("utilDate:" + utilDate);

}

From source file:cn.lynx.emi.license.GenerateLicense.java

public static void main(String[] args) throws ClassNotFoundException, ParseException {
    if (args == null || args.length != 4) {
        System.err.println("Please provide [machine code] [cpu] [memory in gb] [yyyy-MM-dd] as parameter");
        return;/* w ww  .jav  a2s.  c o  m*/
    }

    InputStream is = GenerateLicense.class.getResourceAsStream("/privatekey");
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String key = null;
    try {
        key = br.readLine();
    } catch (IOException e) {
        System.err.println(
                "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath");
        e.printStackTrace();
        return;
    }

    if (key == null) {
        System.err.println(
                "Can't read the private key file, make sure there's a file named \"privatekey\" in the root classpath");
        return;
    }

    String machineCode = args[0];
    int cpu = Integer.parseInt(args[1]);
    long mem = Long.parseLong(args[2]) * 1024 * 1024 * 1024;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    long expDate = sdf.parse(args[3]).getTime();

    LicenseBean lb = new LicenseBean();
    lb.setCpuCount(cpu);
    lb.setMemCount(mem);
    lb.setMachineCode(machineCode);
    lb.setExpireDate(expDate);

    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(baos);
        os.writeObject(lb);
        os.close();

        String serializedLicense = Base64.encodeBase64String(baos.toByteArray());
        System.out.println("License:" + encrypt(key, serializedLicense));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ec.edu.espe.distribuidas.factnosql.test.consultaTotalVentas.java

public static void main(String[] args) throws ParseException {
    PersistenceManager persistence = new PersistenceManager();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Query q = persistence.context().createQuery(Factura.class).field("fechaEmision")
            .equal(sdf.parse("2016-01-27"));
    Iterator<VentasDiarias> aggregate = persistence.context().createAggregation(Factura.class)
            .group("fechaEmision", Group.grouping("total", Group.sum("total")),
                    Group.grouping("count", new Accumulator("$sum", 1)),
                    Group.grouping("fechaEmision", Group.first("fechaEmision")))
            .aggregate(VentasDiarias.class);
    List<VentasDiarias> totalVentas = IteratorUtils.toList(aggregate);
    for (VentasDiarias p : totalVentas)
        System.out.println(p);/*w  w  w  . j av a2  s.co m*/

}

From source file:Main.java

public static void main(String[] args) {
    String maxDate = "15012009";
    SimpleDateFormat fromFormat = new SimpleDateFormat("ddMMyyyy");
    SimpleDateFormat toFormat = new SimpleDateFormat("MMMM dd, yyyy");
    Date date = null;//  w w w. j  ava2  s. c  o m
    try {
        date = fromFormat.parse(maxDate);
    } catch (java.text.ParseException e) {
        e.printStackTrace();
    }
    System.out.println("formated date:-" + toFormat.format(date));
}

From source file:com.pymmasoftware.demo.loyalty.client.StandaloneLoyaltyClient.java

public static void main(String[] args) throws InterruptedException, ParseException {
    ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/application-context.xml");

    StandaloneLoyaltyClient loyaltyClient = context.getBean(StandaloneLoyaltyClient.class);
    Ticket ticket = new Ticket();
    ticket.setAmount(1000.0f);//from   w ww.j  a v a2s  .  c  o  m
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    ticket.setDateTicket(sdf.parse("01/01/2012"));
    ticket.setId("1");

    Card loyaltyCard = new Card();
    loyaltyCard.setCartType("Gold");
    loyaltyCard.setName("VISA");
    loyaltyCard.setName("4859569558");
    Customer customer = new Customer();
    customer.setCustomerID("12");
    customer.setBirthDate(sdf.parse("23/08/1968"));
    customer.setName("Heron");
    customer.setSurName("Nicolas");
    customer.setGender(Gender.Mr);
    loyaltyCard.setCustomer(customer);
    ticket.setLoyaltyCard(loyaltyCard);
    Provider provider = new Provider();
    provider.setName("Pymma Software");
    provider.setCountry("fr");
    Price price = new Price();
    price.setCurrency(Currency.Euro);
    price.setPrice(new Float("100.0"));
    Product product = new Product();
    product.setPrice(price);
    product.setProvider(provider);
    product.setId("100-100");
    product.setName("Pampers");
    ticket.AddLine(product, new Float("100.0"), 10);

    while (true) {
        ticket = loyaltyClient.fireAllRules(ticket);
        logger.info("Ticket processed : {}", ticket);
        sleep(30000);
    }

}

From source file:ec.edu.espe.distribuidas.factnosql.test.consultaPersonas.java

public static void main(String[] args) throws ParseException {
    PersistenceManager persistence = new PersistenceManager();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Query q = persistence.context().createQuery(Factura.class).field("fechaEmision")
            .equal(sdf.parse("2016-01-27"));
    Iterator<ProductoSum> aggregate = persistence.context().createAggregation(Factura.class).match(q)
            .unwind("detalle")
            .group("detalle.producto", Group.grouping("count", Group.sum("detalle.cantidad")),
                    Group.grouping("fecha", Group.first("fechaEmision")),
                    Group.grouping("codigo", Group.first("detalle.codigo")))
            .aggregate(ProductoSum.class);
    List<ProductoSum> presonasS = IteratorUtils.toList(aggregate);
    for (ProductoSum p : presonasS)
        System.out.println(p);//from  ww  w .  j  av  a2s . c  o m

}