Example usage for java.util Date toString

List of usage examples for java.util Date toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Converts this Date object to a String of the form:
 dow mon dd hh:mm:ss zzz yyyy
where:
  • dow is the day of the week ( Sun, Mon, Tue, Wed, Thu, Fri, Sat ).

    Usage

    From source file:com.todopl.foreign.msexchange.MSExchange.java

    public static void main(String[] args) {
    
        try {/*from   w w w  .  j a  v a 2  s  .c  om*/
            Date from = new Date();
            Date to = DateUtils.addDays(from, 5);
    
            System.out.println("Appointments from today " + from.toString());
    
            Pair<String, FindItemsResults<Appointment>> result = getEvents(null, from, to, "USER", "PASS", "EMAIL");
    
            System.out.println("This is your version: " + result.getLeft());
    
            System.out.println("These are your appointments:");
            System.out.println();
    
            for (Appointment a : result.getRight().getItems()) {
    
                System.out.println("Subject==== " + a.getSubject());
                System.out.println("From======= " + a.getStart());
                System.out.println("To========= " + a.getEnd());
                System.out.println("Id========= " + a.getId());
                System.out.println();
            }
    
            System.out.println("Now with the version filled in:");
            Pair<String, FindItemsResults<Appointment>> result2 = getEvents(result.getLeft(), from, to, "USER",
                    "PASSWD", "EMAIL");
            System.out.println("This is your version: " + result2.getLeft().toString());
    
            System.out.println("These are your appointments:");
            System.out.println();
    
            for (Appointment a : result2.getRight().getItems()) {
                System.out.println("Subject==== " + a.getSubject());
                System.out.println("From======= " + a.getStart());
                System.out.println("To========= " + a.getEnd());
                System.out.println();
            }
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    From source file:net.kolola.msgparsercli.MsgParseCLI.java

    public static void main(String[] args) {
    
        // Parse options
    
        OptionParser parser = new OptionParser("f:a:bi?*");
        OptionSet options = parser.parse(args);
    
        // Get the filename
        if (!options.has("f")) {
            System.err.print("Specify a msg file with the -f option");
            System.exit(0);//from   www . j  av  a 2 s  .  c o m
        }
    
        File file = new File((String) options.valueOf("f"));
    
        MsgParser msgp = new MsgParser();
        Message msg = null;
    
        try {
            msg = msgp.parseMsg(file);
        } catch (UnsupportedOperationException | IOException e) {
            System.err.print("File does not exist or is not a valid msg file");
            //e.printStackTrace();
            System.exit(1);
        }
    
        // Show info (as JSON)
        if (options.has("i")) {
            Map<String, Object> data = new HashMap<String, Object>();
    
            String date;
    
            try {
                Date st = msg.getClientSubmitTime();
                date = st.toString();
            } catch (Exception g) {
                try {
                    date = msg.getDate().toString();
                } catch (Exception e) {
                    date = "[UNAVAILABLE]";
                }
            }
    
            data.put("date", date);
            data.put("subject", msg.getSubject());
            data.put("from", "\"" + msg.getFromName() + "\" <" + msg.getFromEmail() + ">");
            data.put("to", "\"" + msg.getToRecipient().toString());
    
            String cc = "";
            for (RecipientEntry r : msg.getCcRecipients()) {
                if (cc.length() > 0)
                    cc.concat("; ");
    
                cc.concat(r.toString());
            }
    
            data.put("cc", cc);
    
            data.put("body_html", msg.getBodyHTML());
            data.put("body_rtf", msg.getBodyRTF());
            data.put("body_text", msg.getBodyText());
    
            // Attachments
            List<Map<String, String>> atts = new ArrayList<Map<String, String>>();
            for (Attachment a : msg.getAttachments()) {
                HashMap<String, String> info = new HashMap<String, String>();
    
                if (a instanceof FileAttachment) {
                    FileAttachment fa = (FileAttachment) a;
    
                    info.put("type", "file");
                    info.put("filename", fa.getFilename());
                    info.put("size", Long.toString(fa.getSize()));
                } else {
                    info.put("type", "message");
                }
    
                atts.add(info);
            }
    
            data.put("attachments", atts);
    
            JSONObject json = new JSONObject(data);
    
            try {
                System.out.print(json.toString(4));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    
        // OR return an attachment in BASE64
        else if (options.has("a")) {
            Integer anum = Integer.parseInt((String) options.valueOf("a"));
    
            Encoder b64 = Base64.getEncoder();
    
            List<Attachment> atts = msg.getAttachments();
    
            if (atts.size() <= anum) {
                System.out.print("Attachment " + anum.toString() + " does not exist");
            }
    
            Attachment att = atts.get(anum);
    
            if (att instanceof FileAttachment) {
                FileAttachment fatt = (FileAttachment) att;
                System.out.print(b64.encodeToString(fatt.getData()));
            } else {
                System.err.print("Attachment " + anum.toString() + " is a message - That's not implemented yet :(");
            }
        }
        // OR print the message body
        else if (options.has("b")) {
            System.out.print(msg.getConvertedBodyHTML());
        } else {
            System.err.print(
                    "Specify either -i to return msg information or -a <num> to print an attachment as a BASE64 string");
        }
    
    }
    

    From source file:Example2.java

    public static void main(String args[])
            throws IOException, ParseException, DScabiClientException, DScabiException, java.text.ParseException {
        System.out.println("Example2");
    
        DMeta meta = new DMeta("localhost", "5000");
    
        DFile f = new DFile(meta);
        f.setNamespace("MyOrg.MyFiles");
        Date date = new Date();
    
        f.put("scabi:MyOrg.MyFiles:myfile1.txt", "myfile1.txt");
        f.put("myfile2.txt", "myfile2.txt");
    
        FileInputStream fis = new FileInputStream("myfile3.txt");
        f.put("scabi:MyOrg.MyFiles:myfile3.txt", fis);
        fis.close();//  ww w .ja v a 2 s.  c o  m
    
        f.copy("scabi:MyOrg.MyFiles:myfile4.txt", "scabi:MyOrg.MyFiles:myfile1.txt");
        f.copy("myfile5.txt", "scabi:MyOrg.MyFiles:myfile1.txt");
    
        f.get("scabi:MyOrg.MyFiles:myfile1.txt", "fileout1" + "_" + date.toString() + ".txt");
        f.get("myfile2.txt", "fileout2" + "_" + date.toString() + ".txt");
    
        FileOutputStream fos = new FileOutputStream("fileout3" + "_" + date.toString() + ".txt");
        f.get("scabi:MyOrg.MyFiles:myfile1.txt", fos);
        fos.close();
    
        FileOutputStream fos2 = new FileOutputStream("fileout4" + "_" + date.toString() + ".txt");
        f.get("myfile2.txt", fos2);
        fos2.close();
    
        f.close();
        meta.close();
    }
    

    From source file:Main.java

    /** Convert a calendar date into a string as specified by http://tools.ietf.org/html/rfc822#section-5.1
     * @param date the calendar instance to convert to a string
     * @param locale the locale to use when outputting strings such as a day of the week, or month of the year.
     * @return a string in the format: "day_abbreviation, day_of_month month_abbreviation year hour:minute:second GMT"
     *//*from  w  ww  .j a  v  a2 s . co m*/
    // package-private - unused
    static final String convertDateToStringRfc822(Calendar date, Locale locale) {
        Date a = Date.from(Instant.now());
        a.toString();
        int day = date.get(Calendar.DAY_OF_MONTH);
        int hour = date.get(Calendar.HOUR_OF_DAY);
        int minute = date.get(Calendar.MINUTE);
        int second = date.get(Calendar.SECOND);
        String str = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale) + ", "
                + (day < 10 ? "0" + day : day) + " " + date.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale)
                + " " + date.get(Calendar.YEAR) + " " + (hour < 10 ? "0" + hour : hour) + ":"
                + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second) + " GMT";
        return str;
    }
    

    From source file:Main.java

    public static String getTimeStampString(Date date) {
        return date == null ? "N/I" : date.toString();
    }
    

    From source file:Main.java

    public static String getTime1() {
    
        java.util.Date date1 = new java.util.Date();
        return date1.toString();
    }
    

    From source file:Main.java

    public static String convertDateToString(Date d) {
        try {//from w  ww.  jav a  2s.  c  o  m
            return gmtFormat.parse(d.toString()).toString();
        } catch (ParseException e) {
    
        }
        return null;
    }
    

    From source file:Main.java

    public static long getDifferenceinMinutes(Date date1, Date date2) {
        System.out.println(date1.toString());
    
        System.out.println(date2.toString());
    
        if (date1 == null || date2 == null)
            return 0;
    
        long diff = date2.getTime() - date1.getTime();
    
        long diffMinutes = TimeUnit.MINUTES.convert(diff, TimeUnit.MILLISECONDS);
    
        return diffMinutes;
    }
    

    From source file:Main.java

    public static String getEDate(String str) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(str, pos);
        String j = strtodate.toString();
        String[] k = j.split(" ");
        return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);
    }
    

    From source file:Main.java

    public static String formatDisplayDate(Date date, String inputFormat) {
        return formatDisplayDate(date.toString(), inputFormat);
    }