Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

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

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale) 

Source Link

Document

Gets the date/time formatter with the given formatting styles for the given locale.

Usage

From source file:com.arcao.menza.fragment.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    Preference feedBackPref = findPreference("feedback");
    feedBackPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//from  w  w w. ja  v a2s. co  m
        public boolean onPreferenceClick(Preference preference) {
            FeedbackHelper.sendFeedBack(getActivity(), R.string.feedback_email, R.string.feedback_subject,
                    R.string.feedback_message);
            return true;
        }
    });

    Preference licensesPref = findPreference("licenses");
    licensesPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent i = new Intent(getActivity(), WebViewActivity.class);
            i.putExtra(WebViewActivity.PARAM_TITLE, R.string.pref_licenses);
            i.putExtra(WebViewActivity.PARAM_RAW_RESOURCE, R.raw.licenses);
            startActivity(i);
            return true;
        }
    });

    findPreference("version").setSummary(getVersion(getActivity()) + " (" + BuildConfig.GIT_SHA + ")");
    try {
        findPreference("build_time").setSummary(DateFormat
                .getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT,
                        getResources().getConfiguration().locale)
                .format(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parse(BuildConfig.BUILD_TIME)));
    } catch (ParseException e) {
        Log.e(TAG, e.getMessage(), e);
    }

    // fix for Android 2.x
    updateListPreferenceSummary(PrefConstant.PRICE_GROUP);
    updateListPreferenceSummary(PrefConstant.DEFAULT_PLACE);
}

From source file:at.becast.youploader.youtube.GuiUploadEvent.java

@Override
public void onInit() {
    this.starttime = System.currentTimeMillis();
    this.lastdata = 0;
    this.lasttime = this.starttime;
    this.lastdb = this.starttime;
    Date in = new Date(this.starttime);
    LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
    Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
            Locale.getDefault());
    frame.getlblStart().setText(formatter.format(out));
    frame.getProgressBar().setString("0,00 %");
    frame.getProgressBar().setValue(0);/*from   w  w  w.  j  a  v a  2s  .  com*/
    frame.getProgressBar().revalidate();
    frame.getBtnCancel().setEnabled(true);
    frame.getBtnEdit().setEnabled(true);
    frame.getBtnDelete().setEnabled(false);
    frame.revalidate();
    frame.repaint();
}

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 av  a  2s  .  c  o 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:de.perdian.commons.lang.conversion.impl.converters.StringToDateConverter.java

@Override
protected DateFormat resolveDefaultFormat(Locale locale) {
    String pattern = this.getPattern();
    if (pattern != null) {
        return new SimpleDateFormat(pattern, locale);
    } else {//  w ww  . j a v a  2 s . c om
        Class<? extends Date> targetDateClass = this.getTargetDateClass();
        if (targetDateClass == null || targetDateClass.equals(java.util.Date.class)
                || targetDateClass.equals(java.sql.Date.class)) {
            return DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
        } else if (targetDateClass.equals(java.sql.Timestamp.class)) {
            return DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale);
        } else if (targetDateClass.equals(java.sql.Time.class)) {
            return DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
        } else {
            return DateFormat.getInstance();
        }
    }
}

From source file:com.distributedapplication.springcontrollers.TestController.java

@RequestMapping(value = "/home", method = RequestMethod.GET)
public String homeTest(Locale locale, Model model) {
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    //serverTime is a model attribute to passed to the view 
    // it will bounded to the view
    model.addAttribute("serverTime", formattedDate);

    return "home"; //name of .jsp to be invoked
}

From source file:com.robestone.hudson.compactcolumns.CompactColumnsTest.java

public void doTestDateTimeFormats(Locale locale, int dateFormatType, int timeFormatType, String expect) {
    DateFormat format = DateFormat.getDateTimeInstance(dateFormatType, timeFormatType, locale);
    long time = 1277416568304L;
    Date date = new Date(time);
    String output = format.format(date);
    assertEquals(expect, output);//from   w ww  . j a v  a  2s.  c  o m
}

From source file:de.uniwue.info6.webapp.admin.SubmissionRow.java

public String getEntryDate() {
    if (userEntry != null) {
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL,
                new Locale("de", "DE"));
        return df.format(userEntry.getEntryTime());
    }/*from  w  w  w.  ja  v  a  2s.c  o m*/
    return "---";
}

From source file:com.limegroup.gnutella.gui.GUIUtils.java

static void resetLocale() {
    NUMBER_FORMAT0 = NumberFormat.getNumberInstance(GUIMediator.getLocale());
    NUMBER_FORMAT0.setMaximumFractionDigits(0);
    NUMBER_FORMAT0.setMinimumFractionDigits(0);
    NUMBER_FORMAT0.setGroupingUsed(true);

    NUMBER_FORMAT1 = NumberFormat.getNumberInstance(GUIMediator.getLocale());
    NUMBER_FORMAT1.setMaximumFractionDigits(1);
    NUMBER_FORMAT1.setMinimumFractionDigits(1);
    NUMBER_FORMAT1.setGroupingUsed(true);

    DATETIME_FORMAT = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT,
            GUIMediator.getLocale());//from   ww w. j a v  a 2  s  .co  m

    FULL_DATETIME_FORMAT = new SimpleDateFormat("EEE, MMM. d, yyyy h:mm a", GUIMediator.getLocale());

    GENERAL_UNIT_KILOBYTES = I18n.tr("KB");
    GENERAL_UNIT_MEGABYTES = I18n.tr("MB");
    GENERAL_UNIT_GIGABYTES = I18n.tr("GB");
    GENERAL_UNIT_TERABYTES = I18n.tr("TB");
    GENERAL_UNIT_KBPSEC = I18n.tr("KB/s");
}

From source file:org.olat.core.util.StringHelper.java

/**
 * @param date//from  w w  w.  jav a 2  s  .  co m
 * @param locale
 * @return formatted date/time
 */
public static String formatLocaleDateTime(long date, Locale locale) {
    if (date == -1)
        return "-";
    return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format(new Date(date));
}

From source file:org.olat.core.util.Formatter.java

License:asdf

/**
 * formats the given date so it is friendly to read
 * //from ww  w . j  a va 2 s.  com
 * @param d the date
 * @return a String with the formatted date and time
 */
public String formatDateAndTime(Date d) {
    if (d == null)
        return null;
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
    df.setLenient(false);
    String da = df.format(d);
    return da;
}