Четверг
09-05-2024
03:55
Главная страница
Каталог статей
Информист Приветствую Вас Гость | RSS
Регистрация
Вход
Меню сайта

Категории каталога
Delphi [3]
C++ [5]
Java [28]
программирование на Java
Assembler [4]
Алгоритмы на ассме
C# [1]
Eclipse [1]

Наш опрос
Насколько вам понравился этот сайт
Всего ответов: 545

Копилка
Если вам понравился наш сайт или вы нашли полезную информацию, то у вас есть возможность отблагодарить администрацию.

Начало » Статьи » Programming » Java

Formatting a Date Using a Custom Format

A pattern of special characters is used to specify the format of the date. This example demonstrates some of the characters. For a complete listing, see the javadoc documentation for the SimpleDateFormat class.

Note: This example formats dates using the default locale (which, in the author's case, is Locale.ENGLISH). If the example is run in a different locale, the text (e.g., month names) will not be the same.


 Format formatter;
 
 // The year
 formatter = new SimpleDateFormat("yy"); // 02
 formatter = new SimpleDateFormat("yyyy"); // 2002
 
 // The month
 formatter = new SimpleDateFormat("M"); // 1
 formatter = new SimpleDateFormat("MM"); // 01
 formatter = new SimpleDateFormat("MMM"); // Jan
 formatter = new SimpleDateFormat("MMMM"); // January
 
 // The day
 formatter = new SimpleDateFormat("d"); // 9
 formatter = new SimpleDateFormat("dd"); // 09
 
 // The day in week
 formatter = new SimpleDateFormat("E"); // Wed
 formatter = new SimpleDateFormat("EEEE"); // Wednesday
 
 // Get today's date
 Date date = new Date();
 
 // Some examples
 formatter = new SimpleDateFormat("MM/dd/yy");
 String s = formatter.format(date);
 // 01/09/02
 
 formatter = new SimpleDateFormat("dd-MMM-yy");
 s = formatter.format(date);
 // 29-Jan-02
 
 // Examples with date and time; see also
 // e316 Formatting the Time Using a Custom Format
 formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
 s = formatter.format(date);
 // 2002.01.29.08.36.33
 
 formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
 s = formatter.format(date);
 // Tue, 09 Jan 2002 22:14:02 -0500


Источник: http://www.exampledepot.com/egs/java.text/FormatDate.html
Категория: Java | Добавил: Judge (04-01-2010)
Просмотров: 2056 | Рейтинг: 5.0 |

Всего комментариев: 0
Имя *:
Email *:
Код *:
Форма входа

Поиск по каталогу
Яндекс


Поиск по Информисту

Наша кнопка


Друзья сайта

Статистика


Copyright MyCorp © 2006Сайт создан в системе uCoz