Example usage for java.text DateFormat LONG

List of usage examples for java.text DateFormat LONG

Introduction

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

Prototype

int LONG

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

Click Source Link

Document

Constant for long style pattern.

Usage

From source file:ilearn.orb.controller.AnnotationController.java

@RequestMapping(value = "/annotation")
public ModelAndView textAnnotation(Locale locale, ModelMap modelMap, HttpServletRequest request,
        HttpSession session) {//from  ww w  .  j a v a2s.c o  m

    try {
        request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    // System.err.println(request.getRemoteAddr());
    // System.err.println(request.getRemoteHost());
    // System.err.println(request.getRemotePort());
    txModule = new TextAnnotationModule();
    ModelAndView model = new ModelAndView();
    model.setViewName("annotation");
    try {
        Gson gson = new GsonBuilder().registerTypeAdapter(java.util.Date.class, new UtilDateDeserializer())
                .setDateFormat(DateFormat.LONG).create();
        User[] students = null;
        try {
            String json = UserServices.getProfiles(Integer.parseInt(session.getAttribute("id").toString()),
                    session.getAttribute("auth").toString());
            students = gson.fromJson(json, User[].class);
        } catch (NullPointerException e) {
        }
        if (students == null || students.length == 0) {
            students = HardcodedUsers.defaultStudents();
        }
        modelMap.put("students", students);
        String text = request.getParameter("inputText");
        String profileId = request.getParameter("selectedId");
        if (text != null) {
            text = new String(text.getBytes("8859_1"), "UTF-8");
        } else
            text = "";
        modelMap.put("profileId", profileId);
        modelMap.put("text", text);
        // UserProfile pr = retrieveProfile(session,
        // Integer.parseInt(profileId));
    } catch (NumberFormatException e) {
        //e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return model;
}

From source file:org.linesofcode.alltrack.graph.AddValueActivity.java

private void initializeContent() {
    calendar = Calendar.getInstance();
    dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
    timeFormat = new SimpleDateFormat(TIME_PATTERN, Locale.getDefault());

    dateView = (TextView) findViewById(R.id.add_value_date);
    timeView = (TextView) findViewById(R.id.add_value_time);

    Button okButton = (Button) findViewById(R.id.add_value_ok);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override/*  w  ww  .j a  v  a2s. c  o m*/
        public void onClick(View v) {
            addValue();
        }
    });

    Button cancelButton = (Button) findViewById(R.id.add_value_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED, new Intent(ADD_VALUE_ACTION_CODE));
            finish();
        }
    });

    EditText value = (EditText) findViewById(R.id.add_value_value);
    value.setOnKeyListener(new View.OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    addValue();
                    return true;
                }
            }
            return false;
        }
    });

    dateView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDatePicker();
        }
    });

    timeView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTimePicker();
        }
    });

    updateDateTimeFields();

    Bundle extras = getIntent().getExtras();
    graphId = extras.getInt("graphId");
    position = extras.getInt("position");
    Log.d(TAG, "Starting addValue Activity for graph [" + graphId + "] in position [" + position + "].");
    graph = graphService.getById(graphId);
}

From source file:org.jamwiki.utils.DateUtil.java

/**
 * Given a string, return the matching DateFormat style (SHORT, LONG, etc)
 * or -1 if there is no corresponding style.
 *//* w ww . j av a2  s  .  c  o m*/
public static int stringToDateFormatStyle(String format) {
    if (StringUtils.equalsIgnoreCase(format, "SHORT")) {
        return DateFormat.SHORT;
    } else if (StringUtils.equalsIgnoreCase(format, "MEDIUM")) {
        return DateFormat.MEDIUM;
    } else if (StringUtils.equalsIgnoreCase(format, "LONG")) {
        return DateFormat.LONG;
    } else if (StringUtils.equalsIgnoreCase(format, "FULL")) {
        return DateFormat.FULL;
    } else if (StringUtils.equalsIgnoreCase(format, "DEFAULT")) {
        return DateFormat.DEFAULT;
    }
    return -1;
}

From source file:org.jactr.tools.async.iterative.tracker.IterativeRunTracker.java

public IterativeRunTracker() {
    _ioHandler = new BaseIOHandler();
    _ioHandler.addReceivedMessageHandler(StatusMessage.class, new MessageHandler<StatusMessage>() {

        public void handleMessage(IoSession arg0, StatusMessage message) throws Exception {
            update(message);//from   www  .  j a  v  a2 s  .com

            if (LOGGER.isDebugEnabled()) {
                StringBuilder sb = new StringBuilder();
                sb.append(message.getIteration()).append("/").append(message.getTotalIterations());
                if (message.isStart())
                    sb.append(" started @ ");
                else
                    sb.append(" stopped @ ");

                DateFormat format = DateFormat.getTimeInstance(DateFormat.LONG);
                sb.append(format.format(new Date(message.getWhen())));
                LOGGER.debug(sb.toString());
                LOGGER.debug("Will finish @ " + format.format(new Date(getETA())) + " in "
                        + getTimeToCompletion() + "ms");
            }
        }
    });

    _ioHandler.addReceivedMessageHandler(ExceptionMessage.class, new MessageHandler<ExceptionMessage>() {

        public void handleMessage(IoSession arg0, ExceptionMessage message) throws Exception {
            update(message);
            if (LOGGER.isDebugEnabled()) {
                StringBuilder sb = new StringBuilder("Exception thrown during iteration ");
                sb.append(message.getIteration()).append(" by ").append(message.getModelName()).append(" ");
                LOGGER.debug(sb.toString(), message.getThrown());
            }
        }
    });

    _ioHandler.addReceivedMessageHandler(DeadLockMessage.class, new MessageHandler<DeadLockMessage>() {

        public void handleMessage(IoSession session, DeadLockMessage message) throws Exception {
            /**
             * Error : error
             */
            LOGGER.error("Deadlock has been detected, notifying");
            if (_listener != null)
                _listener.deadlockDetected();
        }
    });
}

From source file:com.h57.sample.controller.HomeController.java

/**
 * Does some simple work to find the current shiro subject gets a list of
 * services, and the date./*from  w w  w  .j  a v  a  2 s  .  co  m*/
 */
@RequestMapping(method = RequestMethod.GET, value = { "/", "/index" })
public String home(Locale locale, Model model, HttpServletRequest request) {
    logger.info("Welcome home! the client locale is " + locale.toString());

    // This gets the current subject from shiro
    Subject currentUser = SecurityUtils.getSubject();

    // I was going to have more services, who knows .. maybe we will add
    // more.
    List<String> services = new ArrayList<String>();
    // My SQL class org.apache.commons.dbcp.BasicDataSource
    if (dataSource instanceof BasicDataSource) {
        services.add("Data Source: " + ((BasicDataSource) dataSource).getUrl());
    } else if (dataSource instanceof SimpleDriverDataSource) {
        services.add("Data Source: " + ((SimpleDriverDataSource) dataSource).getUrl());
    }

    services.add("My SQL: " + dataSource.getClass());

    // Just to prove we can do it.
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);

    // Lets get an identity object
    Identity thisIdentity = null;

    // Remembered (from cookie) is different from authenticated in Shiro
    if (currentUser.isRemembered()) {
        logger.info("Remembered PRINCIPAL: " + currentUser.getPrincipal());
        thisIdentity = identityService.getIdentity(currentUser.getPrincipal().toString());

        // Authenticated, we really do believe they are who they claim to
        // be!
    } else if (currentUser.isAuthenticated()) {
        logger.info("Authenticated PRINCIPAL: " + currentUser.getPrincipal());
        thisIdentity = identityService.getIdentity(currentUser.getPrincipal().toString());
    }

    // Pass this to the jsp.
    model.addAttribute("currentUser", currentUser);
    model.addAttribute("identity", thisIdentity);
    model.addAttribute("serverTime", formattedDate);
    model.addAttribute("services", services);
    return "home";
}

From source file:com.espian.ticktock.AddEditActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.menu_add:
        ContentValues cvs = new ContentValues();
        String label = mTitle.getText().toString();
        if (label == null || label.isEmpty()) {
            Toast.makeText(this, R.string.no_empty_label, Toast.LENGTH_SHORT).show();
            return true;
        }//from ww  w .j  ava2s  .  c  om
        cvs.put("label", label);
        cvs.put("date", DateFormat.getDateInstance(DateFormat.LONG).format(mDatePicker.getSelectedDate()));
        if (isEdit) {

            int updateResult = getContentResolver().update(TickTockProvider.countdownUri, cvs,
                    BaseColumns._ID + "=?", new String[] { editId + "" });
            if (updateResult == 1) {
                setResult(RESULT_OK);
                finish();
            } else {
                Toast.makeText(this, getString(R.string.failed_update, mTitle.getText().toString()),
                        Toast.LENGTH_SHORT).show();
            }

        } else {
            Uri result = getContentResolver().insert(TickTockProvider.countdownUri, cvs);
            if (result != null) {
                setResult(RESULT_OK);
                finish();
            } else {
                Toast.makeText(this, getString(R.string.failed_add, mTitle.getText().toString()),
                        Toast.LENGTH_SHORT).show();
            }
        }
        break;

    case R.id.menu_discard:
        setResult(RESULT_CANCELED);
        finish();
        break;

    }
    return true;
}

From source file:de.fau.amos4.model.Employee.java

public Map<String, String> getFields() {
    Map<String, String> allFields = new LinkedHashMap<String, String>();
    Locale locale = LocaleContextHolder.getLocale();
    DateFormat format = DateFormat.getDateInstance(DateFormat.LONG, locale);
    DateFormat df;/* www  .j  a va 2s. c o m*/
    if (locale.getLanguage().equals("de")) {
        df = new SimpleDateFormat("dd.MM.yyyy");
    } else {
        df = new SimpleDateFormat("dd/MM/yyyy");
    }

    allFields.put(AppContext.getApplicationContext().getMessage("employee.id", null, locale),
            Long.toString(getId()));
    allFields.put(AppContext.getApplicationContext().getMessage("client.companyName", null, locale),
            getClient().getCompanyName());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.personnelNumber", null, locale),
            Long.toString(getPersonnelNumber()));
    allFields.put(AppContext.getApplicationContext().getMessage("employee.firstName", null, locale),
            getFirstName());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.familyName", null, locale),
            getFamilyName());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.maidenName", null, locale),
            getMaidenName());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.birthDate", null, locale),
            format.format(getBirthDate()));
    allFields.put(AppContext.getApplicationContext().getMessage("employee.placeOfBirth", null, locale),
            getPlaceOfBirth());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.countryOfBirth", null, locale),
            getCountryOfBirth());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.street", null, locale), getStreet());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.houseNumber", null, locale),
            getHouseNumber());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.additionToAddress", null, locale),
            getAdditionToAddress());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.city", null, locale), getCity());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.zipCode", null, locale),
            getZipCode());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.sex", null, locale),
            getSex().toString());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.maritalStatus", null, locale),
            getMaritalStatus().toString());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.disabled", null, locale),
            getDisabled().toString());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.citizenship", null, locale),
            getCitizenship());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.socialInsuranceNumber", null, locale),
            getSocialInsuranceNumber());
    allFields.put(
            AppContext.getApplicationContext().getMessage("employee.employerSocialSavingsNumber", null, locale),
            getEmployerSocialSavingsNumber());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.iban", null, locale), getIban());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.bic", null, locale), getBic());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.employment", null, locale),
            getEmployment());
    allFields.put(AppContext.getApplicationContext().getMessage("employee.temporaryEmployment", null, locale),
            getTemporaryEmployment());
    //allFields.put( AppContext.getApplicationContext().getMessage("employee.token", null, locale), getToken());
    return allFields;
}

From source file:lucee.commons.i18n.FormatUtil.java

public static DateFormat[] getDateFormats(Locale locale, TimeZone tz, boolean lenient) {
    String id = "d-" + locale.hashCode() + "-" + tz.getID() + "-" + lenient;
    DateFormat[] df = formats.get(id);
    if (df == null) {
        List<DateFormat> list = new ArrayList<DateFormat>();
        list.add(DateFormat.getDateInstance(DateFormat.FULL, locale));
        list.add(DateFormat.getDateInstance(DateFormat.LONG, locale));
        list.add(DateFormat.getDateInstance(DateFormat.MEDIUM, locale));
        list.add(DateFormat.getDateInstance(DateFormat.SHORT, locale));
        addCustom(list, locale, FORMAT_TYPE_DATE);
        df = list.toArray(new DateFormat[list.size()]);

        for (int i = 0; i < df.length; i++) {
            df[i].setLenient(lenient);/*from ww w  . j  a va 2  s.com*/
            df[i].setTimeZone(tz);
        }
        formats.put(id, df);
    }
    return df;
}

From source file:ilearn.orb.controller.ProfilesController.java

@RequestMapping(value = "/profiles/{userid}", method = RequestMethod.GET)
public ModelAndView userProfile(Locale locale, @PathVariable("userid") Integer userid, ModelMap modelMap,
        HttpSession session) {/* ww  w. j av a 2 s .  c  o m*/

    ModelAndView model = new ModelAndView();
    model.setViewName("profiles");

    try {
        String json;
        User[] students = null;
        UserProfile p = null;
        User selectedStudent = null;
        if (userid < 0) {
            students = HardcodedUsers.defaultStudents();
            selectedStudent = selectedStudent(students, userid.intValue());
            //p = HardcodedUsers.defaultProfile(selectedStudent.getId());
            json = UserServices.getDefaultProfile(HardcodedUsers.defaultProfileLanguage(userid));
            if (json != null)
                p = new Gson().fromJson(json, UserProfile.class);
        } else {
            Gson gson = new GsonBuilder().registerTypeAdapter(java.util.Date.class, new UtilDateDeserializer())
                    .setDateFormat(DateFormat.LONG).create();
            json = UserServices.getProfiles(Integer.parseInt(session.getAttribute("id").toString()),
                    session.getAttribute("auth").toString());
            students = gson.fromJson(json, User[].class);
            selectedStudent = selectedStudent(students, userid.intValue());

            json = UserServices.getJsonProfile(userid, session.getAttribute("auth").toString());
            if (json != null)
                p = new Gson().fromJson(json, UserProfile.class);
        }
        String dataForCircles = "";
        if (p != null) {
            String categories = "[";
            dataForCircles = "[";
            ProblemDescription probs[][] = p.getUserProblems().getProblems().getProblems();
            for (int i = 0; i < probs.length; i++) {
                for (int j = 0; j < probs[i].length; j++) {
                    dataForCircles = dataForCircles + "[" + i + ", " + p.getUserProblems().getUserSeverity(i, j)
                            + ",\"" + probs[i][j].getHumanReadableDescription() + "\"]";
                    if (i != probs.length - 1 || j != probs[i].length - 1)
                        dataForCircles = dataForCircles + ", ";
                }
                categories = categories + "\"" + p.getUserProblems().getProblemDefinition(i).getUri() + "\"";
                if (i != probs.length - 1)
                    categories = categories + ", ";
            }
            categories = categories + "]";
            dataForCircles = dataForCircles + "], " + categories + ", " + probs.length + ", \""
                    + p.getLanguage() + "\"";
        }
        modelMap.put("selectedStudent", selectedStudent);
        modelMap.put("students", students);
        modelMap.put("selectedProfile", p);
        modelMap.put("dataForCircles", dataForCircles);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return model;

}

From source file:net.kjmaster.cookiemom.booth.add.AddBoothDialogFragment.java

private void showDateTimeDialog() {
    // Create the dialog
    final Dialog mDateTimeDialog = new Dialog(getActivity());
    // Inflate the root layout
    final RelativeLayout mDateTimeDialogView = (RelativeLayout) getActivity().getLayoutInflater()
            .inflate(R.layout.ui_date_time_dialog, null);
    // Grab widget instance
    final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
            .findViewById(R.id.DateTimePicker);
    // Check is system is set to use 24h time (this doesn't seem to work as expected though)
    final String timeS = android.provider.Settings.System.getString(getActivity().getContentResolver(),
            android.provider.Settings.System.TIME_12_24);
    final boolean is24h = !(timeS == null || timeS.equals("12"));

    // Update demo TextViews when the "OK" button is clicked
    mDateTimeDialogView.findViewById(R.id.SetDateTime).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            mDateTimePicker.clearFocus();
            // TODO Auto-generated method stub

            String eventDate = SimpleDateFormat.getDateInstance(DateFormat.LONG)
                    .format(new Date(mDateTimePicker.getDateTimeMillis()));
            ((TextView) getActivity().findViewById(R.id.Date)).setText(eventDate);
            if (mDateTimePicker.is24HourView()) {
                ((TextView) getActivity().findViewById(R.id.Time)).setText(
                        mDateTimePicker.get(Calendar.HOUR_OF_DAY) + ":" + mDateTimePicker.get(Calendar.MINUTE));
            } else {
                NumberFormat fmt = NumberFormat.getNumberInstance();
                fmt.setMinimumIntegerDigits(2);

                ((TextView) getActivity().findViewById(R.id.Time))
                        .setText(fmt.format(mDateTimePicker.get(Calendar.HOUR)) + ":"
                                + fmt.format(mDateTimePicker.get(Calendar.MINUTE)) + " "
                                + (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM"));

            }/*from w w w  .  j a v a2 s .  c om*/

            hiddenDateTime.setText(String.valueOf(mDateTimePicker.getDateTimeMillis()));
            mDateTimeDialog.dismiss();
        }
    });

    // Cancel the dialog when the "Cancel" button is clicked
    mDateTimeDialogView.findViewById(R.id.CancelDialog).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            mDateTimeDialog.cancel();
        }
    });

    // Reset Date and Time pickers when the "Reset" button is clicked
    mDateTimeDialogView.findViewById(R.id.ResetDateTime).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            mDateTimePicker.reset();
        }
    });

    // Setup TimePicker
    mDateTimePicker.setIs24HourView(is24h);
    // No title on the dialog window
    mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Set the dialog content view
    mDateTimeDialog.setContentView(mDateTimeDialogView);
    // Display the dialog
    mDateTimeDialog.show();
}