List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:Main.java
public static void main(String[] args) throws Exception { File fileToChange = new File("C:/myfile.txt"); Date filetime = new Date(fileToChange.lastModified()); System.out.println(filetime.toString()); System.out.println(fileToChange.setLastModified(System.currentTimeMillis())); filetime = new Date(fileToChange.lastModified()); System.out.println(filetime.toString()); }
From source file:Main.java
public static void main(String[] args) throws Exception { Date d = new Date(); Class cls = d.getClass();/*from www . j a v a 2 s . co m*/ System.out.println("Time = " + d.toString()); Object obj = cls.newInstance(); System.out.println("Time = " + obj); }
From source file:Main.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Date date = new Date(); final JLabel timeLabel = new JLabel(date.toString()); Timer timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { date.setTime(System.currentTimeMillis()); timeLabel.setText(date.toString()); }/*from ww w .j a v a2 s. c om*/ }); timer.start(); JOptionPane.showMessageDialog(null, timeLabel); } }); }
From source file:Main.java
public static void main(String[] args) { // create a date Date date = new Date(); // print the string representation System.out.println("String : " + date.toString()); }
From source file:Main.java
public static void main(String[] args) { java.util.Date javaDate = new java.util.Date(); long javaTime = javaDate.getTime(); System.out.println("The Java Date is: " + javaDate.toString()); java.sql.Date sqlDate = new java.sql.Date(javaTime); System.out.println("The SQL DATE is: " + sqlDate.toString()); java.sql.Time sqlTime = new java.sql.Time(javaTime); System.out.println("The SQL TIME is: " + sqlTime.toString()); java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(javaTime); System.out.println("The SQL TIMESTAMP is: " + sqlTimestamp.toString()); }
From source file:DateDemo.java
public static void main(String[] args) { //+//from w ww.j a v a 2 s . c om Date dNow = new Date(); /* Simple, Java 1.0 date printing */ System.out.println("It is now " + dNow.toString()); // Use a SimpleDateFormat to print the date our way. SimpleDateFormat formatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz"); System.out.println("It is " + formatter.format(dNow)); //- }
From source file:Main.java
public static void main(String[] args) { java.util.Date javaDate = new java.util.Date(); long javaTime = javaDate.getTime(); System.out.println("The Java Date is:" + javaDate.toString()); // SQL DATE//from ww w . j av a 2s . c o m java.sql.Date sqlDate = new java.sql.Date(javaTime); System.out.println("The SQL DATE is: " + sqlDate.toString()); // SQL TIME java.sql.Time sqlTime = new java.sql.Time(javaTime); System.out.println("The SQL TIME is: " + sqlTime.toString()); // SQL TIMESTAMP java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(javaTime); System.out.println("The SQL TIMESTAMP is: " + sqlTimestamp.toString()); }
From source file:Main.java
public static void main(String[] args) { // create a date Date date = new Date(); // clone it to a second date Object date2 = date.clone();/*from w ww. j a v a 2 s .com*/ // print the results System.out.println("Original Date:" + date.toString()); System.out.println("Cloned date :" + date2.toString()); }
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; }/*from www . j a v a 2 s .com*/ 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:Main.java
public static void main(String[] args) { Calendar someTime = Calendar.getInstance(); someTime.set(Calendar.HOUR_OF_DAY, 17); someTime.set(Calendar.MINUTE, 0); someTime.set(Calendar.SECOND, 0); // convert it to java epoch date Date someDate = toEpochDate(someTime); // create a date object from java.sql.Time Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime()); // now do the comparison System.out.println("Some Date: " + someDate.toString()); System.out.println("Sql Time: " + fromSqlTime.toString()); System.out.println("Are they equal? " + someDate.equals(fromSqlTime)); }