Tabnine Logo
Format
Code IndexAdd Tabnine to your IDE (free)

How to use
Format
in
java.text

Best Java code snippets using java.text.Format (Showing top 20 results out of 74,097)

Refine searchRefine arrow

  • DecimalFormat
  • NumberFormat
  • SimpleDateFormat
  • Date
  • DateFormat
  • BigDecimal
  • DecimalFormatSymbols
  • Calendar
origin: stackoverflow.com

 public String convertTime(long time){
  Date date = new Date(time);
  Format format = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
  return format.format(date);
}
origin: pentaho/pentaho-kettle

public static Object getFiscalDate( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
 Object FunctionContext ) {
 if ( ArgList.length == 2 ) {
  try {
   if ( isNull( ArgList ) ) {
    return null;
   } else if ( isUndefined( ArgList ) ) {
    return undefinedValue;
   }
   java.util.Date dIn = (java.util.Date) ArgList[0];
   Calendar startDate = Calendar.getInstance();
   Calendar fisStartDate = Calendar.getInstance();
   Calendar fisOffsetDate = Calendar.getInstance();
   startDate.setTime( dIn );
   Format dfFormatter = new SimpleDateFormat( "dd.MM.yyyy" );
   String strOffsetDate = (String) ArgList[1] + String.valueOf( startDate.get( Calendar.YEAR ) );
   java.util.Date dOffset = (java.util.Date) dfFormatter.parseObject( strOffsetDate );
   fisOffsetDate.setTime( dOffset );
   String strFisStartDate = "01.01." + String.valueOf( startDate.get( Calendar.YEAR ) + 1 );
   fisStartDate.setTime( (java.util.Date) dfFormatter.parseObject( strFisStartDate ) );
   int iDaysToAdd = (int) ( ( startDate.getTimeInMillis() - fisOffsetDate.getTimeInMillis() ) / 86400000 );
   fisStartDate.add( Calendar.DATE, iDaysToAdd );
   return fisStartDate.getTime();
  } catch ( Exception e ) {
   throw new RuntimeException( e.toString() );
  }
 } else {
  throw new RuntimeException( "The function call getFiscalDate requires 2 arguments." );
 }
}
origin: robovm/robovm

/**
 * Returns a new instance of {@code DateFormat} with the same properties.
 */
@Override
public Object clone() {
  DateFormat clone = (DateFormat) super.clone();
  clone.calendar = (Calendar) calendar.clone();
  clone.numberFormat = (NumberFormat) numberFormat.clone();
  return clone;
}
origin: stackoverflow.com

 return fDelegate.format( obj, toAppendTo, pos );
 return fDelegate.formatToCharacterIterator( obj );
public Object parseObject( String source, ParsePosition pos ) {
 int initialIndex = pos.getIndex();
 Object result = fDelegate.parseObject( source, pos );
 if ( result != null && pos.getIndex() < source.length() ) {
  int errorIndex = pos.getIndex();
origin: stackoverflow.com

 SimpleDateFormat dateFormat = new SimpleDateFormat ("HH:MM:ss.");
DecimalFormat fractionalformat = new DecimalFormat ("00");

Date date = new Date ();

String str = dateFormat.format (date) + fractionalformat.format (date.getTime () % 1000L / 10L);

System.out.println (str);
origin: com.liferay.portal/com.liferay.portal.kernel

@Override
public Date parse(String source, ParsePosition pos) {
  Format dateFormatDate = FastDateFormatFactoryUtil.getDate(
    _locale, _timeZone);
  DateFormat dateFormatDateTime = DateFormatFactoryUtil.getDateTime(
    _locale, _timeZone);
  Date today = new Date();
  String dateString = source.substring(pos.getIndex());
  if (dateString.startsWith(_todayString)) {
    dateString = dateString.replaceFirst(
      _todayString, dateFormatDate.format(today));
  }
  else if (dateString.startsWith(_yesterdayString)) {
    Calendar cal = Calendar.getInstance(_timeZone, _locale);
    cal.setTime(today);
    cal.add(Calendar.DATE, -1);
    Date yesterday = cal.getTime();
    dateString = dateString.replaceFirst(
      _todayString, dateFormatDate.format(yesterday));
  }
  return dateFormatDateTime.parse(dateString, new ParsePosition(0));
}
origin: stackoverflow.com

 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mma");
Date timenow = new Date(System.currentTimeMillis());
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("Europe/Istanbul"));
cal.setTime(timenow);
String formatedTime = sdf.format(cal);

or 

StringBuffer sb = new StringBuffer();
DateFormat.getInstance(DateFormat.DATETIME_DEFAULT).formatLocal(sb,System.currentTimeMillis());
String localFormatedDate = sb.toString();
origin: plutext/docx4j

DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Format formatter = new SimpleDateFormat(format);
org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
  date = (Date)dateTimeFormat.parse(r);
} catch (ParseException e) {
  try {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    date = (Date) dateFormat.parse(r);
  } catch (ParseException e2) {
    log.warn(e.getMessage());
    date = new Date();
String result = formatter.format(date);
origin: stackoverflow.com

 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentTime = df.format(new Date());
Timestamp timestamp = Timestamp.valueOf(currentTime)
//will print without showing the .x part
String currentTimeFromTimestamp = df.format(currentTime);
origin: stackoverflow.com

localSimpleDateFormat = new ThreadLocal<SimpleDateFormat>() {
  protected SimpleDateFormat initialValue() {
    return new SimpleDateFormat();
localSimpleDateFormat = new ThreadLocal<SimpleDateFormat>() {
  protected SimpleDateFormat initialValue() {
    return new SimpleDateFormat(pattern);
localSimpleDateFormat = new ThreadLocal<SimpleDateFormat>() {
  protected SimpleDateFormat initialValue() {
    return new SimpleDateFormat(pattern, formatSymbols);
return localSimpleDateFormat.get().parseObject(source);
return localSimpleDateFormat.get().parse(source);
return localSimpleDateFormat.get().parseObject(source, pos);
localSimpleDateFormat.get().setCalendar(newCalendar);
origin: knowm/XChart

  new SimpleDateFormat(styler.getDatePattern(), styler.getLocale());
simpleDateformat.setTimeZone(styler.getTimezone());
axisFormat = simpleDateformat;
 tickLabels.add(category.toString());
} else if (axisType == Series.DataType.Number) {
 tickLabels.add(axisFormat.format(new BigDecimal(category.toString()).doubleValue()));
} else if (axisType == Series.DataType.Date) {
 tickLabels.add(axisFormat.format((((Date) category).getTime())));
origin: square/spoon

static String dateToString(long date) {
 return DATE_FORMAT.get().format(new Date(date));
}
origin: stackoverflow.com

Calendar cal= Calendar.getInstance(); //Get the current date
SimpleDateFormat formatter= new SimpleDateFormat("yyyy/MMM/dd"); //format it as per your requirement
String today = formatter.format(cal.getTime());
String lastday = formatter.format(cal.getActualMaximum(Calendar.DATE));
String sql;
sql = "SELECT * FROM ORDERS WHERE DATE BETWEEN " + CONVERT(Char(10), today,112) + " AND " + CONVERT(Char(10), lastday ,112)
origin: stackoverflow.com

 String s;
Format formatter;
Calendar calendar = Calendar.getInstance();
// tp = TimePicker
calendar.set(Calendar.HOUR_OF_DAY, tp.getCurrentHour());
calendar.set(Calendar.MINUTE, tp.setCurrentMinutes());
calendar.clear(Calendar.SECOND); //reset seconds to zero

formatter = new SimpleDateFormat("HH:mm:ss");
s = formatter.format(calendar.getTime()); // 08:00:00
origin: stackoverflow.com

 public class DateLabelFormatter extends AbstractFormatter {

  private String datePattern = "yyyy-MM-dd";
  private SimpleDateFormat dateFormatter = new SimpleDateFormat(datePattern);

  @Override
  public Object stringToValue(String text) throws ParseException {
    return dateFormatter.parseObject(text);
  }

  @Override
  public String valueToString(Object value) throws ParseException {
    if (value != null) {
      Calendar cal = (Calendar) value;
      return dateFormatter.format(cal.getTime());
    }

    return "";
  }

}
origin: pentaho/pentaho-kettle

 if ( dArg1.equals( null ) ) {
  return null;
 Format dfFormatter = new SimpleDateFormat();
 oRC = dfFormatter.format( dArg1 );
} catch ( Exception e ) {
 throw new RuntimeException( "Could not convert to local format." );
 Format dfFormatter = new SimpleDateFormat( sArg2 );
 oRC = dfFormatter.format( dArg1 );
} catch ( Exception e ) {
 throw new RuntimeException( "Could not convert to the given format." );
 if ( sArg3.length() == 2 ) {
  Locale dfLocale = EnvUtil.createLocale( sArg3.toLowerCase() );
  dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
  oRC = dfFormatter.format( dArg1 );
 } else {
  throw new RuntimeException( "Locale is not 2 characters long." );
  Locale dfLocale = EnvUtil.createLocale( sArg3.toLowerCase() );
  dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
  dfFormatter.setTimeZone( tz );
  oRC = dfFormatter.format( dArg1 );
 } else {
  throw new RuntimeException( "Locale is not 2 characters long." );
origin: org.apache.commons/commons-lang3

  @Override
  public void run() {
    for(int j= 0; j<NROUNDS; ++j) {
      try {
        final Date date= new Date();
        final long t0= System.currentTimeMillis();
        final String formattedDate= printer.format(date);
        totalElapsed.addAndGet(0, System.currentTimeMillis() - t0);
        final long t1 = System.currentTimeMillis();
        final Object pd= parser.parseObject(formattedDate);
        totalElapsed.addAndGet(1, System.currentTimeMillis() - t1);
        if(!date.equals(pd)) {
          failures.incrementAndGet();
        }
      } catch (final Exception e) {
        failures.incrementAndGet();
        e.printStackTrace();
      }
    }
  }
});
origin: stackoverflow.com

public String formatDate(String day, String month, String year) {
// Do something with the date chosen by the user
SimpleDateFormat df = new SimpleDateFormat("dd-MMM");
Calendar c = Calendar.getInstance();
c.set(0, Integer.parseInt(month)-1, Integer.parseInt(day));
return df.format(c.getTimeInMillis());
origin: stackoverflow.com

 static public String formatISO8601(Calendar cal) {
MessageFormat format = new MessageFormat("{0,time}{1,number,+00;-00}:{2,number,00}");

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
df.setTimeZone(cal.getTimeZone());
format.setFormat(0, df);

long zoneOff = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET) / 60000L;
int zoneHrs = (int) (zoneOff / 60L);
int zoneMins = (int) (zoneOff % 60L);
if (zoneMins < 0)
  zoneMins = -zoneMins;

return (format.format(new Object[] { cal.getTime(), new Integer(zoneHrs), new Integer(zoneMins) }));
}
origin: stackoverflow.com

 SimpleDateFormat sdf = new SimpleDateFormat(
      "yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));

try {
              Date dt = sdf.parse(sdf.format(Calendar.getInstance()));
            } catch (ParseException e) {
              e.printStackTrace();
            }
java.textFormat

Javadoc

The base class for all formats.

This is an abstract base class which specifies the protocol for classes which convert other objects or values, such as numeric values and dates, and their string representations. In some cases these representations may be localized or contain localized characters or strings. For example, a numeric formatter such as DecimalFormat may convert a numeric value such as 12345 to the string "$12,345". It may also parse the string back into a numeric value. A date and time formatter like SimpleDateFormat may represent a specific date, encoded numerically, as a string such as "Wednesday, February 26, 1997 AD".

Many of the concrete subclasses of Format employ the notion of a pattern. A pattern is a string representation of the rules which govern the conversion between values and strings. For example, a DecimalFormatobject may be associated with the pattern "$#,##0.00;($#,##0.00)", which is a common US English format for currency values, yielding strings such as "$1,234.45" for 1234.45, and "($987.65)" for -987.6543. The specific syntax of a pattern is defined by each subclass. Even though many subclasses use patterns, the notion of a pattern is not inherent to Format classes in general, and is not part of the explicit base class protocol.

Two complex formatting classes are worth mentioning: MessageFormatand ChoiceFormat. ChoiceFormat is a subclass of NumberFormat which allows the user to format different number ranges as strings. For instance, 0 may be represented as "no files", 1 as "one file", and any number greater than 1 as "many files". MessageFormatis a formatter which utilizes other Format objects to format a string containing multiple values. For instance, a MessageFormat object might produce the string "There are no files on the disk MyDisk on February 27, 1997." given the arguments 0, "MyDisk", and the date value of 2/27/97. See the ChoiceFormat and MessageFormat descriptions for further information.

Most used methods

  • format
  • parseObject
  • clone
    Returns a copy of this Format instance.
  • formatToCharacterIterator
    Formats the specified object using the rules of this format and returns an AttributedCharacterIterat
  • upTo
  • upToWithQuotes
  • <init>
    Used by subclasses. This was public in Java 5.
  • createAttributedCharacterIterator
    Creates an AttributedCharacterIterator containg the concatenated contents of the passed inAttributed

Popular in Java

  • Reading from database using SQL prepared statement
  • setScale (BigDecimal)
  • getApplicationContext (Context)
  • setContentView (Activity)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Permission (java.security)
    Legacy security code; do not use.
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now