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:com.intuit.utils.PopulateUsers.java

public static void main(String[] args) {
    Date now = new Date();
    System.out.println("Current date is: " + now.toString());

    MongoClient mongo = new MongoClient("localhost", 27017);
    DB db = mongo.getDB("tweetsdb");
    DBCollection collection = db.getCollection("userscollection");
    WriteResult result = collection.remove(new BasicDBObject());

    int userIndex = 1;
    for (int i = 1; i <= 10; i++) {
        JSONObject userDocument = new JSONObject();
        String user = "user" + userIndex;
        userDocument.put("user", user);

        JSONArray followerList = new JSONArray();
        Random randomGenerator = new Random();
        for (int j = 0; j < 3; j++) {
            int followerId = randomGenerator.nextInt(10) + 1;
            // Assumption here is, a user will not be a follower on himself
            while (followerId == userIndex) {
                followerId = randomGenerator.nextInt(10) + 1;
            }/*w  w  w  .ja  v a  2s . c  o  m*/

            String follower = "user" + followerId;
            if (!followerList.contains(follower)) {
                followerList.add(follower);
            }
        }
        userDocument.put("followers", followerList);

        JSONArray followingList = new JSONArray();
        for (int k = 0; k < 3; k++) {
            int followingId = randomGenerator.nextInt(10) + 1;
            // Assumption here is, a user will not be following his own tweets
            while (followingId == userIndex) {
                followingId = randomGenerator.nextInt(10) + 1;
            }

            String followingUser = "user" + followingId;
            if (!followingList.contains(followingUser)) {
                followingList.add(followingUser);
            }
        }
        userDocument.put("following", followingList);
        System.out.println("Json string is: " + userDocument.toString());
        DBObject userDBObject = (DBObject) JSON.parse(userDocument.toString());
        collection.insert(userDBObject);
        userIndex++;

    }

    //        try {
    //            FileWriter file = new FileWriter("/Users/dmurty/Documents/MongoData/usersCollection.js");
    //            file.write(usersArray.toJSONString());
    //            file.flush();
    //            file.close();
    //        } catch (IOException ex) {
    //            Logger.getLogger(PopulateUsers.class.getName()).log(Level.SEVERE, null, ex);
    //        } 
}

From source file:JFormattedTextFieldDateInputSampleDateFormatSHORT.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Date/Time Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label;/*from  w w w.j  ava  2s.co m*/
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format shortDate = DateFormat.getDateInstance(DateFormat.SHORT);
    label = new JLabel("Short date:");
    input = new JFormattedTextField(shortDate);
    input.setValue(new Date());
    input.setColumns(20);

    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);

    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    DateFormatSymbols symbols = new DateFormatSymbols(new Locale("en", "US"));
    String[] defaultDays = symbols.getShortWeekdays();

    for (int i = 0; i < defaultDays.length; i++) {
        System.out.print(defaultDays[i] + "  ");
    }//from   w  w w.j ava 2s  .  c  om
    System.out.println();

    String[] capitalDays = { "", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
    symbols.setShortWeekdays(capitalDays);

    String[] modifiedDays = symbols.getShortWeekdays();
    for (int i = 0; i < modifiedDays.length; i++) {
        System.out.println(modifiedDays[i] + "  ");
    }

    SimpleDateFormat formatter = new SimpleDateFormat("E", symbols);
    Date today = new Date();
    String result = formatter.format(today);
    System.out.println(result);

}

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));
    System.out.println("UTC Time: "
            + DateFormatUtils.formatUTC(now, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()));

}

From source file:com.bia.config.Main.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/applicationContext*.xml");

    EmployeeCassandraServiceImpl service = context.getBean(EmployeeCassandraServiceImpl.class);

    Emp emp = new Emp();
    emp.setId((new Date()).toString());
    String username = "IM-" + new Date();
    emp.setUsername(username);/*from   ww w.ja  v  a2s .c om*/
    emp.setJoinDate(new Date());
    emp.setStorageSize(10.0);
    emp.setContent(ByteBuffer
            .wrap(IOUtils.toByteArray(Main.class.getClassLoader().getResourceAsStream("log4j.properties"))));

    service.saveEmployee(emp);
    int count = 0;
    for (Emp e : service.findAllEmployees()) {
        System.out.println(e + String.valueOf(e.getContent()));
        System.out.println(new String(e.getContent().array()));
        count++;
    }

    System.out.println("done " + count);

    System.out.println(service.findByUsername(username));

}

From source file:JFormattedTextFieldDateInputSampleELocaleFRENCH.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Date/Time Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label;/*  w w w.ja v a2 s .  c  om*/
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format dayOfWeek = new SimpleDateFormat("E", Locale.FRENCH);
    label = new JLabel("French day of week:");
    input = new JFormattedTextField(dayOfWeek);
    input.setValue(new Date());
    input.setColumns(20);

    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);

    frame.add(panel);
    frame.add(new JTextField());
    frame.pack();
    frame.setVisible(true);
}

From source file:JFormattedTextFieldDateInputSampleDateFormatFULLLocaleUS.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Date/Time Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label;/*from   w  w w  .j  a  va2 s. co  m*/
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format fullUSDate = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
    label = new JLabel("Full US date:");
    input = new JFormattedTextField(fullUSDate);
    input.setValue(new Date());
    input.setColumns(20);

    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);

    frame.add(panel);
    frame.add(new JTextField());
    frame.pack();
    frame.setVisible(true);
}

From source file:br.com.joaops.springdatajpajavaconfigfirebird.Main.java

public static void main(String[] args) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            DataConfiguration.class)) {
        BookService service = context.getBean(BookService.class);
        Book book = new Book("First Book", new Date(), 33, new BigDecimal(26.50));
        service.save(book);/*from   w w  w.  ja  v a  2  s  .c o m*/
        List<Book> books = service.findAll();
        for (Book b : books) {
            System.out.println(b);
        }
    }
}

From source file:MainClass.java

public static void main(String[] pArgs) throws Exception {
    Date now = new Date();
    Date truncYear = DateUtils.truncate(now, Calendar.YEAR);
    Date truncMonth = DateUtils.truncate(now, Calendar.MONTH);
    System.out.println("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
    System.out.println("truncYear: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(truncYear));
    System.out.println("truncMonth: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(truncMonth));
}

From source file:MainClass.java

public static void main(String[] pArgs) throws Exception {
    //Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));
}