Example usage for java.text DateFormat FULL

List of usage examples for java.text DateFormat FULL

Introduction

In this page you can find the example usage for java.text DateFormat FULL.

Prototype

int FULL

To view the source code for java.text DateFormat FULL.

Click Source Link

Document

Constant for full style pattern.

Usage

From source file:org.northrop.leanne.publisher.Main.java

public static void main(String[] args) {
    CommandLineParser parser = new GnuParser();
    try {//from  www.ja  va  2 s.c  o m
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (args.length == 0 || line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("pub", options);
        } else if (line.hasOption("version")) {
            URLClassLoader cl = (URLClassLoader) Main.class.getClassLoader();
            String title = "";
            String version = "";
            String date = "";
            try {
                URL url = cl.findResource("META-INF/MANIFEST.MF");
                Manifest manifest = new Manifest(url.openStream());
                Attributes attr = manifest.getMainAttributes();
                title = attr.getValue("Implementation-Title");
                version = attr.getValue("Implementation-Version");
                date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM)
                        .format(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(attr.getValue("Built-Date")));
            } catch (Exception e) {
                e.printStackTrace();
            }

            System.out.println("------------------------------------------------------------");
            System.out.println("Publisher Pipeline " + version);
            System.out.println("------------------------------------------------------------");
            System.out.println("");
            System.out.println(title + " build time " + date);
            System.out.println("Java: " + System.getProperty("java.version"));
            System.out.println("JVM:  " + System.getProperty("java.vendor"));
            System.out.println("OS:   " + System.getProperty("os.name") + " " + System.getProperty("os.version")
                    + " " + System.getProperty("os.arch"));
        } else {
            Option[] options = line.getOptions();
            Binding binding = new Binding();
            binding.setVariable("home", System.getProperty("pub.home"));
            binding.setVariable("inputDir", System.getProperty("pub.home") + "/input");
            binding.setVariable("outputDir", System.getProperty("pub.home") + "/output");
            binding.setVariable("appName", System.getProperty("program.name"));
            binding.setVariable("isdebug", false);

            for (int i = 0; i < options.length; i++) {
                Option opt = options[i];
                binding.setVariable("is" + opt.getOpt(), true);
            }

            String[] roots = new String[] { System.getProperty("pub.home") + "/resources/scripts",
                    System.getProperty("pub.home") + "/resources/scripts/formats" };
            ClassLoader parent = Main.class.getClassLoader();
            GroovyScriptEngine gse = new GroovyScriptEngine(roots, parent);

            if (!line.hasOption("rerun")) {
                gse.run("prep.groovy", binding);
            }

            for (String name : getFormats()) {
                if (line.hasOption(name.toLowerCase())) {
                    String file = ("" + name.charAt(0)).toLowerCase() + name.substring(1) + ".groovy";
                    gse.run(file, binding);
                }
            }
        }
    } catch (ParseException exp) {
        System.err.println("Command line parsing failed.  Reason: " + exp.getMessage());
    } catch (ResourceException resourceError) {
        System.err.println("Groovy script failed.  Reason: " + resourceError.getMessage());
    } catch (IOException ioError) {
        System.err.println("Groovy script failed.  Reason: " + ioError.getMessage());
    } catch (ScriptException error) {
        System.err.println("Groovy script failed.  Reason: " + error.getMessage());
        error.printStackTrace();
    }
}

From source file:Main.java

public static String getFormatTime(long time) {
    if (time <= 0) {
        return "";
    }//from   w w  w. java  2 s .  c om
    return SimpleDateFormat.getDateInstance(DateFormat.FULL).format(new Date(time));
}

From source file:DateUtils.java

/**
 * A method to get the current date to use in a timestamp
 *
 * @return  a string containing the timestamp
 *///from w  w w  .j  a  va  2 s  .  co  m
public static String getCurrentDate() {

    GregorianCalendar calendar = new GregorianCalendar();
    DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL);

    return formatter.format(calendar.getTime());

}

From source file:DateUtils.java

/**
 * A method to get the current date and time to use in a timestamp
 *
 * @return  a string containing the timestamp
 *//*from  w ww  .j  av  a2 s. co  m*/
public static String getCurrentDateAndTime() {

    GregorianCalendar calendar = new GregorianCalendar();
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    return formatter.format(calendar.getTime());

}

From source file:Main.java

public static String DateMessage(Date d, Context c) {
    DateFormat df = DateFormat.getDateTimeInstance();
    DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    DateFormat dfNoTime = DateFormat.getDateInstance();
    DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
    DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
    DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH);
    DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c);

    String s = dfDevice.format(d) + " or \n" + dfS.format(d) + " or \n" + dfM.format(d) + " or \n"
            + dfL.format(d) + " or \n" + dfF.format(d);

    return s;/*w ww.ja v  a2  s.  co m*/

}

From source file:DateLocaleServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //Get the client's Locale
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale);
    String welcome = bundle.getString("Welcome");
    String date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(new Date());

    //Display the locale
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html><head><title>" + welcome + "</title></head><body>");

    out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>");

    out.println(date + "<br /><br />");

    java.util.Enumeration e = bundle.getKeys();
    while (e.hasMoreElements()) {

        out.println((String) e.nextElement());
        out.println("<br /><br />");

    }// w  w w .java  2 s .co m

    out.println("Locale: ");
    out.println(locale.getLanguage() + "_" + locale.getCountry());

    out.println("</body></html>");

}

From source file:Main.java

public static Date FormatDate(String sRecDate, Context c) {
    DateFormat df = DateFormat.getDateTimeInstance();
    DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    DateFormat dfNoTime = DateFormat.getDateInstance();
    DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
    DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
    DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH);
    DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c);

    Date dRecDate = null;//from w w  w. ja  v  a  2  s. c om

    try {
        dRecDate = dfDevice.parse(sRecDate);
    } catch (ParseException e) {
        try {
            dRecDate = df.parse(sRecDate);
        } catch (ParseException e2) {

            try {
                dRecDate = dfS.parse(sRecDate);
            } catch (ParseException e3) {

                try {
                    dRecDate = dfM.parse(sRecDate);
                } catch (ParseException e4) {

                    try {
                        dRecDate = dfL.parse(sRecDate);
                    } catch (ParseException e5) {

                        try {
                            dRecDate = dfF.parse(sRecDate);
                        } catch (ParseException e6) {

                            try {
                                dRecDate = dfNoTime.parse(sRecDate);
                            } catch (ParseException e7) {

                                try {
                                    dRecDate = dfSNoTime.parse(sRecDate);
                                } catch (ParseException e8) {

                                    try {
                                        dRecDate = dfMNoTime.parse(sRecDate);
                                    } catch (ParseException e9) {

                                        try {
                                            dRecDate = dfLNoTime.parse(sRecDate);
                                        } catch (ParseException e10) {

                                            try {
                                                dRecDate = dfFNoTime.parse(sRecDate);
                                            } catch (ParseException e11) {

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return dRecDate;

}

From source file:org.jboss.tools.openshift.internal.common.ui.utils.DateTimeUtils.java

public static String formatSince(String value, TimeZone timezone) {
    try {//from w  ww.  j  a  v a2 s.  c  o  m
        Date date = parse(value);
        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL);
        if (timezone != null) {
            formatter.setTimeZone(timezone);
        }
        return formatter.format(date);
    } catch (ParseException e) {
        OpenShiftCommonUIActivator.getDefault().getLogger()
                .logWarning("Unable to parse format duration value: " + value, e);
    }
    return value;
}

From source file:com.vityuk.ginger.provider.format.JdkDateUtils.java

private static int createJdkDateStyleCode(DateFormatStyle formatStyle) {
    switch (formatStyle) {
    case SHORT://from  w  ww  .  jav  a 2s .c o m
        return DateFormat.SHORT;
    case MEDIUM:
        return DateFormat.MEDIUM;
    case LONG:
        return DateFormat.LONG;
    case FULL:
        return DateFormat.FULL;
    case DEFAULT:
        return DateFormat.DEFAULT;
    default:
        throw new IllegalArgumentException();
    }
}

From source file:com.m2dl.mini_projet.mini_projet_android.fragment.MarkerDialogFragment.java

public static MarkerDialogFragment newInstance(Photo myPhoto) {
    MarkerDialogFragment dialogMarker = new MarkerDialogFragment();
    Bundle args = new Bundle();
    args.putString(ARG_AUTHOR, myPhoto.getAuthor());
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
    args.putString(ARG_DATE, dateFormat.format(myPhoto.getDate()));
    ArrayList<String> myArrayList = new ArrayList<>();
    for (Tag tag : myPhoto.getTags()) {
        myArrayList.add(tag.getNom());//from   w  w w. j av  a2  s  . co  m
    }
    args.putStringArrayList(ARG_TAGS, myArrayList);
    args.putString(ARG_URL, myPhoto.getUrl());
    dialogMarker.setArguments(args);
    return dialogMarker;
}