Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER Copyright 2011 IBM. All rights reserved. Use is subject to license terms. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at You can also obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 package org.odftoolkit.simple.common.field;
 import java.util.Date;
DateField displays a date, by default this is the current date.

 public class DateField extends Field {

The default date format of date field.
 	private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

The default date value format.
 	private static final String DEFAULT_DATE_VALUE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.S";
 	// package constructor, only called by Fields.
 	DateField(OdfElement odfElement) {
 		TextSpanElement spanElement = ((OdfFileDomodfElement.getOwnerDocument()).newOdfElement(TextSpanElement.class);
 		 = spanElement.newTextDateElement();
 		OdfNumberDateStyle dateStyle = newDateStyle();
 		String dateStyleName = dateStyle.getStyleNameAttribute();
 		Calendar calender = Calendar.getInstance();
 		Date date = calender.getTime();
 		String svalue = simpleFormat.format(date);

Set the format of this date field. Date format pattern is the same as SimpleDateFormat.

formatString the format string of this date.
See also:
 	public void formatDate(String formatString) {
 		try {
 			Date simpleDate = simpleFormat.parse(sValue);
 			SimpleDateFormat newFormat = new SimpleDateFormat(formatString);
 		} catch (ParseException e) {
 			Logger.getLogger(DateField.class.getName()).log(.e.getMessage(), e);

Set whether the date value of this field is fixed.

isFixed if true, the date value shall be preserved, otherwise it may be replaced with a new value in future edits.
	public void setFixed(boolean isFixed) {

Return an instance of TextDateElement which represents this feature.

an instance of TextDateElement
		return ;
	// Create an <code>OdfNumberDateStyle</code> element
		return newStyle;
		String unique_name;
		do {
			unique_name = String.format("N%06x", (int) (Math.random() * 0xffffff));
while (styles.getTimeStyle(unique_name) != null);
		return unique_name;
	public FieldType getFieldType() {
New to GrepCode? Check out our FAQ X