当前位置: 首页>>代码示例>>Java>>正文


Java DateFormat类代码示例

本文整理汇总了Java中java.text.DateFormat的典型用法代码示例。如果您正苦于以下问题:Java DateFormat类的具体用法?Java DateFormat怎么用?Java DateFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DateFormat类属于java.text包,在下文中一共展示了DateFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toSqlArray

import java.text.DateFormat; //导入依赖的package包/类
public Array toSqlArray ( final Connection connection, final Event event ) throws SQLException
{
    final DateFormat isoDateFormat = new SimpleDateFormat ( isoDatePatterrn );
    final String[] fields;
    // array must be large enough to hold all attributes plus id and both time stamps
    fields = new String[ ( event.getAttributes ().size () + 3 ) * 2];
    // now populate values
    fields[0] = "id";
    fields[1] = event.getId ().toString ();
    fields[2] = "sourceTimestamp";
    fields[3] = isoDateFormat.format ( event.getSourceTimestamp () );
    fields[4] = "entryTimestamp";
    fields[5] = isoDateFormat.format ( event.getEntryTimestamp () );
    int i = 6;
    for ( final Entry<String, Variant> entry : event.getAttributes ().entrySet () )
    {
        fields[i] = entry.getKey ();
        fields[i + 1] = entry.getValue ().toString ();
        i += 2;
    }
    return connection.createArrayOf ( "text", fields );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:23,代码来源:EventConverter.java

示例2: parseDate

import java.text.DateFormat; //导入依赖的package包/类
/**
 * Try to parse the given date as a HTTP date.
 */
public static final long parseDate(String value, 
                                   DateFormat[] threadLocalformats) {

    Long cachedDate = parseCache.get(value);
    if (cachedDate != null)
        return cachedDate.longValue();

    Long date = null;
    if (threadLocalformats != null) {
        date = internalParseDate(value, threadLocalformats);
        updateParseCache(value, date);
    } else {
        synchronized (parseCache) {
            date = internalParseDate(value, formats);
            updateParseCache(value, date);
        }
    }
    if (date == null) {
        return (-1L);
    } else {
        return date.longValue();
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:FastHttpDateFormat.java

示例3: getXml

import java.text.DateFormat; //导入依赖的package包/类
@Override
public PropBagEx getXml()
{
	DateFormat dateFormatter = getDateFormatter();

	PropBagEx xml = super.getXml();
	xml.setNode("after", dateFormatter.format(afterDate));
	xml.setNode("after/@selected", displayAfter);
	xml.setNode("until", dateFormatter.format(untilDate));
	xml.setNode("until/@selected", displayUntil);
	xml.setNode("visible", visible);
	xml.setNode("track", track);
	xml.setNode("metadata", metadata);
	xml.setNode("sequential", sequential);
	xml.setNode("folder", isFolder || type.equals(FOLDER_TYPE));
	xml.setNode("launch", launch);

	xml.setNode("offlinePath", offlinePath);
	xml.setNode("offlineName", offlineName);

	xml.setNode("type", type);
	String rgb = Integer.toHexString(color.getRGB());
	xml.setNode("colour", rgb.substring(2).toUpperCase());

	return xml;
}
 
开发者ID:equella,项目名称:Equella,代码行数:27,代码来源:BlackboardContent.java

示例4: getGlucoseDatetimesByWeek

import java.text.DateFormat; //导入依赖的package包/类
public List<String> getGlucoseDatetimesByWeek() {
    JodaTimeAndroid.init(mContext);

    DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
    DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());

    DateTime currentDateTime = minDateTime;
    DateTime newDateTime = minDateTime;

    ArrayList<String> finalWeeks = new ArrayList<String>();

    // The number of weeks is at least 1 since we do have average for the current week even if incomplete
    int weeksNumber = Weeks.weeksBetween(minDateTime, maxDateTime).getWeeks() + 1;

    DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    for (int i = 0; i < weeksNumber; i++) {
        newDateTime = currentDateTime.plusWeeks(1);
        finalWeeks.add(inputFormat.format(newDateTime.toDate()));
        currentDateTime = newDateTime;
    }
    return finalWeeks;
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:23,代码来源:DatabaseHandler.java

示例5: getTimeAfterHeadBlockTime

import java.text.DateFormat; //导入依赖的package包/类
public String getTimeAfterHeadBlockTime(int diffInMilSec) {
    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    try {
        Date date = sdf.parse( this.headBlockTime);

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add( Calendar.MILLISECOND, diffInMilSec);
        date = c.getTime();

        return sdf.format(date);

    } catch (ParseException e) {
        e.printStackTrace();
        return this.headBlockTime;
    }
}
 
开发者ID:mithrilcoin-io,项目名称:EosCommander,代码行数:18,代码来源:EosChainInfo.java

示例6: main

import java.text.DateFormat; //导入依赖的package包/类
public static void main(String[] args) {
    String expectedMed = "30-04-2008";
    String expectedShort="30-04-08";

    Locale dk = new Locale("da", "DK");
    DateFormat df1 = DateFormat.getDateInstance(DateFormat.MEDIUM, dk);
    DateFormat df2 = DateFormat.getDateInstance(DateFormat.SHORT, dk);
    String medString = new String (df1.format(new Date(108, Calendar.APRIL, 30)));
    String shortString = new String (df2.format(new Date(108, Calendar.APRIL, 30)));
    System.out.println(df1.format(new Date()));
    System.out.println(df2.format(new Date()));

    if (expectedMed.compareTo(medString) != 0) {
          throw new RuntimeException("Error: " + medString  + " should be " + expectedMed);
      }

    if (expectedShort.compareTo(shortString) != 0) {
          throw new RuntimeException("Error: " + shortString  + " should be " + expectedShort);
      }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Bug5096553.java

示例7: testAddMonth

import java.text.DateFormat; //导入依赖的package包/类
@Test
public void testAddMonth() {

	DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	Calendar cal = new GregorianCalendar(2016, 0, 31);
	System.out.println(format.format(cal.getTime()));
	
	cal.add(Calendar.MONTH, 1);
	System.out.println(format.format(cal.getTime()));
	Assert.assertTrue(cal.getTimeInMillis() == new GregorianCalendar(2016, 1, 29).getTimeInMillis());
	
	cal.add(Calendar.MONTH, 1);
	System.out.println(format.format(cal.getTime()));
	Assert.assertTrue(cal.getTimeInMillis() == new GregorianCalendar(2016, 2, 29).getTimeInMillis());

}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:17,代码来源:DateTests.java

示例8: createFormatInstance

import java.text.DateFormat; //导入依赖的package包/类
protected DateFormat createFormatInstance ( final long timeRange )
{
    if ( hasFormat () )
    {
        try
        {
            return new SimpleDateFormat ( this.format );
        }
        catch ( final IllegalArgumentException e )
        {
            return DateFormat.getInstance ();
        }
    }
    else
    {
        return Helper.makeFormat ( timeRange );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:XAxisDynamicRenderer.java

示例9: onCreateView

import java.text.DateFormat; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.content_about_tab1, container, false);

    TextView about_text_build = (TextView) view.findViewById(R.id.about_text_build);
    TextView about_text_version = (TextView) view.findViewById(R.id.about_text_version);

    String buildDate =  DateFormat.getDateInstance().format(BuildConfig.TIMESTAMP);             //get the build date in locale time format

    if (about_text_build!=null && about_text_version!=null) {
        about_text_version.setText(String.format(Locale.getDefault(),"%s: %s",
                getString(R.string.app_version),BuildConfig.VERSION_NAME));
        about_text_build.setText(String.format(Locale.getDefault(), "%s: %s",
                getResources().getString(R.string.about_build_date), buildDate));
    }

    TextView aboutTextViewGitHubLink = (TextView) view.findViewById(R.id.aboutTextViewGitHubLink);
    aboutTextViewGitHubLink.setMovementMethod(LinkMovementMethod.getInstance());

    TextView aboutTextViewMaterialLicense = (TextView) view.findViewById(R.id.aboutTextViewMaterialLicense);
    aboutTextViewMaterialLicense.setMovementMethod(LinkMovementMethod.getInstance());

    return view;
}
 
开发者ID:TobiasBielefeld,项目名称:Simple-Search,代码行数:25,代码来源:InformationFragment.java

示例10: addNote

import java.text.DateFormat; //导入依赖的package包/类
private void addNote() {
    String noteText = editText.getText().toString();
    editText.setText("");

    final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    String comment = "Added on " + df.format(new Date());

    Note note = new Note();
    note.setText(noteText);
    note.setComment(comment);
    note.setDate(new Date());
    note.setType(NoteType.TEXT);
    noteDao.insert(note);
    Log.d("DaoExample", "Inserted new note, ID: " + note.getId());

    updateNotes();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:NoteActivity.java

示例11: shutdown

import java.text.DateFormat; //导入依赖的package包/类
/**
 * Indicate that the server is shutting down.
 *
 * @param token -- secret token used like a password to authenticate the shutdown command
 * @param delay -- the delay in seconds before jobs are no longer accepted
 */

@GET
@Path("shutdown")
@Produces(MediaType.TEXT_PLAIN)
public Response shutdown(@QueryParam("token") String token, @QueryParam("delay") String delay) throws IOException {
  if (commandLineOptions.shutdownToken == null || token == null) {
    return Response.status(Response.Status.FORBIDDEN).type(MediaType.TEXT_PLAIN_TYPE).entity("No Shutdown Token").build();
  } else if (!token.equals(commandLineOptions.shutdownToken)) {
    return Response.status(Response.Status.FORBIDDEN).type(MediaType.TEXT_PLAIN_TYPE).entity("Invalid Shutdown Token").build();
  } else {
    long shutdownTime = System.currentTimeMillis();
    if (delay != null) {
      try {
        shutdownTime += Integer.parseInt(delay) *1000;
      } catch (NumberFormatException e) {
        // XXX Ignore
      }
    }
    shuttingTime = shutdownTime;
    DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL);
    return Response.ok("ok: Will shutdown at " + dateTimeFormat.format(new Date(shuttingTime)),
        MediaType.TEXT_PLAIN_TYPE).build();
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:31,代码来源:BuildServer.java

示例12: timeLeftDueDateOnClickBehavior

import java.text.DateFormat; //导入依赖的package包/类
@OnClick(R.id.time_left_due_date_content)
void timeLeftDueDateOnClickBehavior() {
    DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            dueCalendar.set(Calendar.YEAR, year);
            dueCalendar.set(Calendar.MONTH, monthOfYear);
            dueCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            DateFormat sdf = android.text.format.DateFormat.getDateFormat(getBaseContext());
            dueDateContent.setText(sdf.format(dueCalendar.getTime()));
            setDate2 = true;
        }
    };
    new DatePickerDialog(this, date,
            dueCalendar.get(Calendar.YEAR),
            dueCalendar.get(Calendar.MONTH),
            dueCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:19,代码来源:OperateTimeLeftActivityBase.java

示例13:

import java.text.DateFormat; //导入依赖的package包/类
/**
 * Parse date with given formatters.
 */
private static final Long internalParseDate
    (String value, DateFormat[] formats) {
    Date date = null;
    for (int i = 0; (date == null) && (i < formats.length); i++) {
        try {
            date = formats[i].parse(value);
        } catch (ParseException e) {
            // Ignore
        }
    }
    if (date == null) {
        return null;
    }
    return Long.valueOf(date.getTime());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:FastHttpDateFormat.java

示例14: parseDateFormat

import java.text.DateFormat; //导入依赖的package包/类
/**
 * Parses a string using {@link SimpleDateFormat} and a given pattern. This
 * method parses a string at the specified parse position and if successful,
 * updates the parse position to the index after the last character used.
 * The parsing is strict and requires months to be less than 12, days to be
 * less than 31, etc.
 *
 * @param s       string to be parsed
 * @param dateFormat Date format
 * @param tz      time zone in which to interpret string. Defaults to the Java
 *                default time zone
 * @param pp      position to start parsing from
 * @return a Calendar initialized with the parsed value, or null if parsing
 * failed. If returned, the Calendar is configured to the GMT time zone.
 */
private static Calendar parseDateFormat(String s, DateFormat dateFormat,
    TimeZone tz, ParsePosition pp) {
  if (tz == null) {
    tz = DEFAULT_ZONE;
  }
  Calendar ret = Calendar.getInstance(tz, Locale.ROOT);
  dateFormat.setCalendar(ret);
  dateFormat.setLenient(false);

  final Date d = dateFormat.parse(s, pp);
  if (null == d) {
    return null;
  }
  ret.setTime(d);
  ret.setTimeZone(UTC_ZONE);
  return ret;
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:33,代码来源:DateTimeUtils.java

示例15: toHtml

import java.text.DateFormat; //导入依赖的package包/类
public String toHtml(){

            HashMap<MemoryLogger.Type, String> typeColours = new HashMap<>();
            typeColours.put(MemoryLogger.Type.info, "#008000"); // LimeGreen
            typeColours.put(MemoryLogger.Type.debug, "blue");
            typeColours.put(MemoryLogger.Type.warn, "orange");
            typeColours.put(MemoryLogger.Type.error, "red");

            String colour = "";
            if (typeColours.containsKey(type))
                colour = typeColours.get(type);

            message = message.replace("\n", "<br/>");

            DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
            String text = dateFormat.format(dateTime) + " > " + tag + " - " + message;

            return "<font color='" + colour + "'>" + text + "</font>";
        }
 
开发者ID:adriankeenan,项目名称:uob-timetable-android,代码行数:20,代码来源:MemoryLogger.java


注:本文中的java.text.DateFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。