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:org.croodie.resource.RootServerResource.java

@Get("json")
public String represent() {
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
            Locale.getDefault());
    String formattedDate = dateFormat.format(date);
    return formattedDate;
}

From source file:com.google.code.gerrytan.jsonsimple.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *//*from   w  w  w  .java  2s.  c  o  m*/
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    logger.info("Welcome home! the client locale is " + locale.toString());

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);

    return "home";
}

From source file:org.openinfinity.web.controller.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *//*www. j  a v  a 2  s.  com*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    LOGGER.info("Welcome home! the client locale is " + locale.toString());
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    String formattedDate = dateFormat.format(date);
    model.addAttribute("serverTime", formattedDate);
    return "home";
}

From source file:com.gelecekonline.web.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *///from ww  w .  j a  va 2s.  c  om
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    logger.info("Welcome home! the client locale is " + locale.toString());

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);

    return "home";
}

From source file:com.skplanet.payment.sample.controller.SampleController.java

/**
 * Simply selects the home view to render by returning its name.
 */// www  . j ava  2 s . co  m
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    logger.info("Welcome home! The client locale is {}.", locale);

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);

    List<HashMap<String, String>> outputs = sqlSession.selectList("userControlMapper.selectSample");
    model.addAttribute("showDB", outputs.toString());

    return "home";
}

From source file:DateFormatDemo.java

static public void showBothStyles(Locale currentLocale) {

    Date today;//from www. ja  va  2  s . c o m
    String result;
    DateFormat formatter;

    int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG,
            DateFormat.FULL };

    System.out.println();
    System.out.println("Locale: " + currentLocale.toString());
    System.out.println();

    today = new Date();

    for (int k = 0; k < styles.length; k++) {
        formatter = DateFormat.getDateTimeInstance(styles[k], styles[k], currentLocale);
        result = formatter.format(today);
        System.out.println(result);
    }
}

From source file:de.interseroh.report.formatters.TimestampFormatter.java

@Override
protected DateFormat getFormatterInstance(Locale locale) {
    return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
}

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

/**
 * Format the given date using the given pattern to return the date
 * as a formatted string.  If the pattern is invalid this method will
 * return <code>null</code>.
 *//*from ww  w .  j  a  va2 s. c  o  m*/
public static String formatDate(Date date, String pattern, String localeString, String timeZoneString,
        DateFormatType dateFormatType) {
    Locale locale = DateUtil.stringToLocale(localeString);
    TimeZone tz = DateUtil.stringToTimeZone(timeZoneString);
    SimpleDateFormat sdf = null;
    int style = DateUtil.stringToDateFormatStyle(pattern);
    if (style != -1 && dateFormatType == DateFormatType.DATE_ONLY) {
        sdf = (SimpleDateFormat) DateFormat.getDateInstance(style, locale);
    } else if (style != -1 && dateFormatType == DateFormatType.TIME_ONLY) {
        sdf = (SimpleDateFormat) DateFormat.getTimeInstance(style, locale);
    } else if (style != -1 && dateFormatType == DateFormatType.DATE_AND_TIME) {
        sdf = (SimpleDateFormat) DateFormat.getDateTimeInstance(style, style, locale);
    } else {
        try {
            sdf = new SimpleDateFormat(pattern, locale);
        } catch (IllegalArgumentException e) {
            String msg = "Attempt to format date with invalid pattern " + pattern
                    + ". If you have customized date or time formats in your "
                    + "jamwiki-configuration.xml file please verify that they are "
                    + "valid java.text.SimpleDateFormat patterns.";
            logger.warn(msg, e);
            return null;
        }
    }
    sdf.setTimeZone(tz);
    return sdf.format(date);
}

From source file:com.theelix.libreexplorer.DetailsDialog.java

@NonNull
@Override// w w w .j a  v a2 s  .  com
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final LayoutInflater factory = getActivity().getLayoutInflater();
    View view = factory.inflate(R.layout.details_dialog, null);
    ((TextView) view.findViewById(R.id.details_name)).setText(file.getName());
    ((TextView) view.findViewById(R.id.details_size)).setText(FileUtilties.getFileSize(file));
    SimpleDateFormat dateFormat = ((SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
            DateFormat.MEDIUM, Locale.getDefault()));
    ((TextView) view.findViewById(R.id.details_lastmodified)).setText(dateFormat.format(file.lastModified()));
    builder.setView(view);
    return builder.create();

}

From source file:au.com.redbarn.liferay.spring.mvc.portlet.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *///from w  ww.  j  av a 2s.  c  om
@RenderMapping
public String home(Locale locale, Model model) {

    log.info("Welcome home! the client locale is " + locale.toString());

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);

    return "home";
}