Example usage for java.util Date toLocaleString

List of usage examples for java.util Date toLocaleString

Introduction

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

Prototype

@Deprecated
public String toLocaleString() 

Source Link

Document

Creates a string representation of this Date object in an implementation-dependent form.

Usage

From source file:it.isislab.dmason.util.SystemManagement.Worker.thrower.DMasonWorker.java

public static void main(String[] args) {
    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();

    ////from   w ww .j a v  a 2 s.c  o m
    // Get name representing the running Java virtual machine.
    // It returns something like 6460@AURORA. Where the value
    // before the @ symbol is the PID.
    //
    String jvmName = bean.getName();

    //Used for log4j properties
    System.setProperty("logfile.name", "worker" + jvmName);

    //Used for log4j properties
    System.setProperty("steplog.name", "workerStep" + jvmName);

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss_SS");
    Date date = new Date();
    dateFormat.format(date);

    System.setProperty("timestamp", date.toLocaleString());

    System.setProperty("paramsfile.name", "params");
    try {
        File logPath = new File("Logs/workers");
        if (logPath.exists())
            FileUtils.cleanDirectory(logPath);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    logger = Logger.getLogger(DMasonWorker.class.getCanonicalName());
    logger.debug("StartWorker " + version);

    autoStart = false;
    connect = false;
    ip = null;
    port = null;
    String topic = "";
    updated = false;
    isBatch = false;
    topicPrefix = "";

    if (args.length == 0) {
        // Force waiting for beacon (requires ActiveMQWrapper)
        autoStart = false;
        connect = true;
    } else if (args.length == 2) {
        // Launched with IP and Port
        ip = args[0];
        port = args[1];
        autoStart = true;
        connect = true;
    } else if (args.length == 4) {
        // Used by D-Mason in order to restart a 
        // worker after update, batch execution, reset
        autoStart = true;
        ip = args[0];
        port = args[1];
        topic = args[2];
        if (args[3].equals("update")) {
            updated = true;
        }
        if (args[3].equals("reset")) {
            updated = false;
            isBatch = false;
        }
        if (args[3].contains("Batch")) {
            updated = false;
            isBatch = true;
            topicPrefix = args[3];
        }
    } else {
        System.out.println("Usage: StartWorker IP PORT");
    }

    DMasonWorker worker = new DMasonWorker(ip, port, topic);

    boolean connected = worker.startConnection();

    if (connected) {
        logger.debug("CONNECTED:");
        logger.debug("   IP     : " + worker.ipAddress.getIPaddress());
        logger.debug("   Port   : " + worker.ipAddress.getPort());
        logger.debug("   Prefix : " + DMasonWorker.topicPrefix);
        logger.debug("   Topic  : " + worker.myTopic);
    } else {
        logger.info("CONNECTION FAILED:");
        logger.debug("   IP     : " + worker.ipAddress.getIPaddress());
        logger.debug("   Port   : " + worker.ipAddress.getPort());
        logger.debug("   Prefix : " + DMasonWorker.topicPrefix);
        logger.debug("   Topic  : " + worker.myTopic);
    }
}

From source file:it.isislab.dmason.util.SystemManagement.Worker.thrower.DMasonWorkerWithGui.java

public static void main(String[] args) {
    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();

    ///*ww  w .ja  v a  2s. c  om*/
    // Get name representing the running Java virtual machine.
    // It returns something like 6460@AURORA. Where the value
    // before the @ symbol is the PID.
    //
    String jvmName = bean.getName();

    //Used for log4j properties
    System.setProperty("logfile.name", "worker" + jvmName);

    //Used for log4j properties
    System.setProperty("steplog.name", "workerStep" + jvmName);

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss_SS");
    Date date = new Date();
    dateFormat.format(date);

    System.setProperty("timestamp", date.toLocaleString());

    System.setProperty("paramsfile.name", "params");
    try {
        File logPath = new File("Logs/workers");
        if (logPath.exists())
            FileUtils.cleanDirectory(logPath);
    } catch (IOException e) {
        //not a problem
    }

    logger = Logger.getLogger(DMasonWorker.class.getCanonicalName());
    logger.debug("StartWorker " + VERSION);

    autoStart = false;

    String ip = null;
    String port = null;
    String topic = "";
    updated = false;
    isBatch = false;
    topicPrefix = "";

    // ip, post, autoconnect
    if (args.length == 3) {
        ip = args[0];
        port = args[1];
        if (args[2].equals("autoconnect")) {
            autoStart = true;
        }
    }
    // ip, post, topic, event 
    if (args.length == 4) {
        autoStart = true;
        if (args[3].equals("update")) {
            updated = true;
        }
        if (args[3].equals("reset")) {
            updated = false;
            isBatch = false;
        }
        if (args[3].contains("Batch")) {
            updated = false;
            isBatch = true;
            topicPrefix = args[3];
        }
        ip = args[0];
        port = args[1];
        topic = args[2];
    }

    /*if(args.length == 2 && args[0].equals("auto"))
    {   autoStart = true;
       updated = true;
       topic = args[1];
    }
    if(args.length == 1 && args[0].equals("auto"))
    {   autoStart = true;
    }*/
    new DMasonWorkerWithGui(autoStart, updated, isBatch, topic, ip, port);
}

From source file:org.jared.synodroid.ds.utils.Utils.java

/**
 * Return a localized date computed/*from ww  w .j a  va  2 s . c  o  m*/
 * 
 * @param secondP
 * @return
 */
public static String computeDate(String secondP) {
    String result = "";
    if (secondP != null && secondP.length() > 0) {
        try {
            long milli = Long.parseLong(secondP) * 1000;
            Date date = new Date(milli);
            result = date.toLocaleString();
        }
        // Nothing to do: not a number
        catch (NumberFormatException ex) {
        }
    }
    return result;
}

From source file:search.java

public static void dumpPart(Part p) throws Exception {
    if (p instanceof Message) {
        Message m = (Message) p;/*from  ww  w  .  j  av  a2 s. c  o m*/
        Address[] a;
        // FROM 
        if ((a = m.getFrom()) != null) {
            for (int j = 0; j < a.length; j++)
                System.out.println("FROM: " + a[j].toString());
        }

        // TO
        if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
            for (int j = 0; j < a.length; j++)
                System.out.println("TO: " + a[j].toString());
        }

        // SUBJECT
        System.out.println("SUBJECT: " + m.getSubject());

        // DATE
        Date d = m.getSentDate();
        System.out.println("SendDate: " + (d != null ? d.toLocaleString() : "UNKNOWN"));

        // FLAGS:
        Flags flags = m.getFlags();
        StringBuffer sb = new StringBuffer();
        Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags

        boolean first = true;
        for (int i = 0; i < sf.length; i++) {
            String s;
            Flags.Flag f = sf[i];
            if (f == Flags.Flag.ANSWERED)
                s = "\\Answered";
            else if (f == Flags.Flag.DELETED)
                s = "\\Deleted";
            else if (f == Flags.Flag.DRAFT)
                s = "\\Draft";
            else if (f == Flags.Flag.FLAGGED)
                s = "\\Flagged";
            else if (f == Flags.Flag.RECENT)
                s = "\\Recent";
            else if (f == Flags.Flag.SEEN)
                s = "\\Seen";
            else
                continue; // skip it
            if (first)
                first = false;
            else
                sb.append(' ');
            sb.append(s);
        }

        String[] uf = flags.getUserFlags(); // get the user flag strings
        for (int i = 0; i < uf.length; i++) {
            if (first)
                first = false;
            else
                sb.append(' ');
            sb.append(uf[i]);
        }
        System.out.println("FLAGS = " + sb.toString());
    }

    System.out.println("CONTENT-TYPE: " + p.getContentType());

    /* Dump input stream
    InputStream is = ((MimeMessage)m).getInputStream();
    int c;
    while ((c = is.read()) != -1)
        System.out.write(c);
    */

    Object o = p.getContent();
    if (o instanceof String) {
        System.out.println("This is a String");
        System.out.println((String) o);
    } else if (o instanceof Multipart) {
        System.out.println("This is a Multipart");
        Multipart mp = (Multipart) o;
        int count = mp.getCount();
        for (int i = 0; i < count; i++)
            dumpPart(mp.getBodyPart(i));
    } else if (o instanceof InputStream) {
        System.out.println("This is just an input stream");
        InputStream is = (InputStream) o;
        int c;
        while ((c = is.read()) != -1)
            System.out.write(c);
    }
}

From source file:search.java

public static void dumpPart(Part p) throws Exception {
    if (p instanceof Message) {
        Message m = (Message) p;//from w  w w. j  a v  a2 s.  c  o  m
        Address[] a;
        // FROM
        if ((a = m.getFrom()) != null) {
            for (int j = 0; j < a.length; j++)
                System.out.println("FROM: " + a[j].toString());
        }

        // TO
        if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
            for (int j = 0; j < a.length; j++)
                System.out.println("TO: " + a[j].toString());
        }

        // SUBJECT
        System.out.println("SUBJECT: " + m.getSubject());

        // DATE
        Date d = m.getSentDate();
        System.out.println("SendDate: " + (d != null ? d.toLocaleString() : "UNKNOWN"));

        // FLAGS:
        Flags flags = m.getFlags();
        StringBuffer sb = new StringBuffer();
        Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags

        boolean first = true;
        for (int i = 0; i < sf.length; i++) {
            String s;
            Flags.Flag f = sf[i];
            if (f == Flags.Flag.ANSWERED)
                s = "\\Answered";
            else if (f == Flags.Flag.DELETED)
                s = "\\Deleted";
            else if (f == Flags.Flag.DRAFT)
                s = "\\Draft";
            else if (f == Flags.Flag.FLAGGED)
                s = "\\Flagged";
            else if (f == Flags.Flag.RECENT)
                s = "\\Recent";
            else if (f == Flags.Flag.SEEN)
                s = "\\Seen";
            else
                continue; // skip it
            if (first)
                first = false;
            else
                sb.append(' ');
            sb.append(s);
        }

        String[] uf = flags.getUserFlags(); // get the user flag strings
        for (int i = 0; i < uf.length; i++) {
            if (first)
                first = false;
            else
                sb.append(' ');
            sb.append(uf[i]);
        }
        System.out.println("FLAGS = " + sb.toString());
    }

    System.out.println("CONTENT-TYPE: " + p.getContentType());

    /*
     * Dump input stream InputStream is = ((MimeMessage)m).getInputStream(); int
     * c; while ((c = is.read()) != -1) System.out.write(c);
     */

    Object o = p.getContent();
    if (o instanceof String) {
        System.out.println("This is a String");
        System.out.println((String) o);
    } else if (o instanceof Multipart) {
        System.out.println("This is a Multipart");
        Multipart mp = (Multipart) o;
        int count = mp.getCount();
        for (int i = 0; i < count; i++)
            dumpPart(mp.getBodyPart(i));
    } else if (o instanceof InputStream) {
        System.out.println("This is just an input stream");
        InputStream is = (InputStream) o;
        int c;
        while ((c = is.read()) != -1)
            System.out.write(c);
    }
}

From source file:it.isislab.dmason.util.SystemManagement.Worker.thrower.DMasonWorkerWithGui.java

public static DMasonWorkerWithGui newInstance(String args[]) {
    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();

    ///*from  w ww  .  java  2s. c o m*/
    // Get name representing the running Java virtual machine.
    // It returns something like 6460@AURORA. Where the value
    // before the @ symbol is the PID.
    //
    String jvmName = bean.getName();

    //Used for log4j properties
    System.setProperty("logfile.name", "worker" + jvmName);

    //Used for log4j properties
    System.setProperty("steplog.name", "workerStep" + jvmName);

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss_SS");
    Date date = new Date();
    dateFormat.format(date);

    System.setProperty("timestamp", date.toLocaleString());

    System.setProperty("paramsfile.name", "params");
    try {
        File logPath = new File("Logs/workers");
        if (logPath.exists())
            FileUtils.cleanDirectory(logPath);
    } catch (IOException e) {
        //not a problem
    }

    logger = Logger.getLogger(DMasonWorker.class.getCanonicalName());
    logger.debug("StartWorker " + VERSION);

    autoStart = false;

    String ip = null;
    String port = null;
    String topic = "";
    updated = false;
    isBatch = false;
    topicPrefix = "";

    // ip, post, autoconnect
    if (args.length == 3) {
        ip = args[0];
        port = args[1];
        if (args[2].equals("autoconnect")) {
            autoStart = true;
        }
    }
    // ip, post, topic, event 
    if (args.length == 4) {
        autoStart = true;
        if (args[3].equals("update")) {
            updated = true;
        }
        if (args[3].equals("reset")) {
            updated = false;
            isBatch = false;
        }
        if (args[3].contains("Batch")) {
            updated = false;
            isBatch = true;
            topicPrefix = args[3];
        }
        ip = args[0];
        port = args[1];
        topic = args[2];
    }

    /*if(args.length == 2 && args[0].equals("auto"))
    {   autoStart = true;
       updated = true;
       topic = args[1];
    }
    if(args.length == 1 && args[0].equals("auto"))
    {   autoStart = true;
    }*/
    return new DMasonWorkerWithGui(autoStart, updated, isBatch, topic, ip, port);
}

From source file:com.octade.droid.ilesansfil.IleSansFil.java

@Override
public void onSaveInstanceState(Bundle outState) {
    Date d = new Date();
    outState.putString("DDD", d.toLocaleString());
    super.onSaveInstanceState(outState);
    Log.i(CURRENTMODULE, "onSaveInstanceState Called");
}

From source file:com.blazeroni.reddit.http.PersistentCookieStore.java

@Override
public void addCookie(Cookie cookie) {
    String name = cookie.getName();

    Date expiryDate = cookie.getExpiryDate();
    if (Log.DEBUG) {
        Log.debug("cookie value: " + cookie.getValue());
        Log.debug("Expiry date: " + (expiryDate == null ? "no expiry date" : expiryDate.toLocaleString()));
        Log.debug("persistent: " + cookie.isPersistent());
        Log.debug("Cookie class: " + cookie.getClass().getCanonicalName());
    }//from  ww w .  j  a v  a  2  s  .c  om

    // Save cookie into local store
    this.cookies.put(name, cookie);

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = this.cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();

}

From source file:rml.controller.ShopController.java

@RequestMapping(value = "/Shop", method = RequestMethod.GET)
@ResponseBody/*from   w ww  .j  ava2 s. co m*/
public Object shopLogin(Shop shop) {

    ReturnJson returnJson = new ReturnJson();
    returnJson.setErrorCode(1000);
    returnJson.setReturnMessage("?");
    returnJson.setServerStatus(0);

    if (StringUtils.isEmpty(shop.getMobile()) || StringUtils.isEmpty(shop.getPassword())) {

        returnJson.setErrorCode(1001);
        returnJson.setReturnMessage("?" + shop.toString());
        returnJson.setServerStatus(1);
        return returnJson;
    }
    String result1 = MD5.GetMD5Code(shop.getRandomKey() + "at^&*ta");
    if (!result1.equals(shop.getSecretKey())) {
        returnJson.setErrorCode(99999);
        returnJson.setReturnMessage("" + shop.toString());
        returnJson.setServerStatus(1);
        return returnJson;
    }
    try {
        shop.setPassword(MD5.GetMD5Code(shop.getPassword()));
        Shop shop1 = shopService.getShop(shop);
        if (shop1 == null) {
            returnJson.setErrorCode(1002);
            returnJson.setReturnMessage("??");
            returnJson.setServerStatus(1);
            return returnJson;
        }
        if (shop1.getStatus() == 1) {
            returnJson.setErrorCode(1003);
            returnJson.setReturnMessage(",");
            returnJson.setServerStatus(1);
            return returnJson;
        }
        if (shop1.getStatus() == 3) {
            returnJson.setErrorCode(1004);
            returnJson.setReturnMessage("");
            returnJson.setServerStatus(1);
            return returnJson;
        }
        Date today = new Date();
        Order order = new Order();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(new Date());
        dateString = dateString + " 00:00:00";
        order.setStartDate(dateString);
        SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
        dateString = formatter1.format(new Date());
        order.setEndDate(dateString);
        order.setShopId(shop1.getUuid());
        int orderDaily = 0;
        try {
            orderDaily = orderService.getShopReport(order);
        } catch (Exception e) {

        }
        Calendar calendar = Calendar.getInstance(Locale.CHINA);
        int YEAR = calendar.getMinimum(Calendar.YEAR);// ???()
        int day = calendar.getMinimum(Calendar.DAY_OF_WEEK);// ???()
        calendar.set(Calendar.YEAR, YEAR);
        calendar.set(Calendar.DAY_OF_WEEK, day);
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.AM_PM, 0);
        calendar.set(Calendar.MINUTE, 0);
        Date date = calendar.getTime();
        int orderTotal = 0;
        order.setStartDate(date.toLocaleString());
        try {
            orderTotal = orderService.getShopReport(order);
        } catch (Exception e) {

        }
        shop1.setMoneyDaily(orderDaily);
        shop1.setMoneyTotal(orderTotal);
        returnJson.setReturnObject(shop1);
    } catch (Exception ex) {
        ex.printStackTrace();
        returnJson.setErrorCode(1005);
        returnJson.setReturnMessage("?");
        returnJson.setServerStatus(2);
        return returnJson;
    }
    return returnJson;
}

From source file:com.evolveum.midpoint.web.page.admin.server.currentState.IterativeInformationPanel.java

private String formatDate(Date date) {
    if (date == null) {
        return null;
    }//from  w  w  w. ja v  a  2s .c  o m
    return date.toLocaleString();
}