當前位置: 首頁>>代碼示例>>Java>>正文


Java DateFormat.getDateTimeInstance方法代碼示例

本文整理匯總了Java中java.text.DateFormat.getDateTimeInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java DateFormat.getDateTimeInstance方法的具體用法?Java DateFormat.getDateTimeInstance怎麽用?Java DateFormat.getDateTimeInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.DateFormat的用法示例。


在下文中一共展示了DateFormat.getDateTimeInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.text.DateFormat; //導入方法依賴的package包/類
public static void main(String[] arg)
        {
                int result = 0;
                Locale loc = new Locale("ko","KR");
                Date now = new Date(108, Calendar.APRIL, 9);

                DateFormat df =
                   DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT,loc);
                SimpleDateFormat sdf = new SimpleDateFormat("",loc);
                sdf.applyPattern("yyyy. M. d a h:mm");
                if( !sdf.format(now).equals(df.format(now))){
                 result++;
                 System.out.println("error at " + sdf.format(now));
                 }
                df =  DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM,loc);
                sdf.applyPattern("yyyy'\ub144' M'\uc6d4' d'\uc77c' '('EE')' a h:mm:ss");
                if( !sdf.format(now).equals(df.format(now))){
                 result++;
                 System.out.println("error at " + sdf.format(now));
                 }
                df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG,loc);
                sdf.applyPattern("yyyy. M. d a h'\uc2dc' mm'\ubd84' ss'\ucd08'");
                if( !sdf.format(now).equals(df.format(now))){
                 result++;
                 System.out.println("error at " + sdf.format(now));
                 }
                df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL,loc);
                sdf.applyPattern("yy. M. d a h'\uc2dc' mm'\ubd84' ss'\ucd08' z");
                if( !sdf.format(now).equals(df.format(now))){
                 result++;
                 System.out.println("error at " + sdf.format(now));
                 }

           if(result > 0) throw new RuntimeException();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:Bug4395196.java

示例2: getCrashReport

import java.text.DateFormat; //導入方法依賴的package包/類
private String getCrashReport(Throwable ex) {
        StringBuffer exceptionStr = new StringBuffer();
//        String mtype = android.os.Build.MODEL; // 手機型號
//        String mtyb= android.os.Build.BRAND;//手機品牌
//        String cpuAbi = android.os.Build.CPU_ABI;//cpu架構
//        String sdk = android.os.Build.VERSION.SDK;//sdk版本號
//        String release = android.os.Build.VERSION.RELEASE;//依賴的係統版本號
//        String device = android.os.Build.DEVICE;//設備
//        String manufacturer = android.os.Build.MANUFACTURER;//手機品牌
        exceptionStr.append("Android: " + android.os.Build.VERSION.RELEASE
                + "(" + android.os.Build.MODEL + ")\n");

        Date date = new Date();
        DateFormat format = DateFormat
                .getDateTimeInstance();
        String t = format.format(date);
        exceptionStr.append("time: " + t + "\n");

        exceptionStr.append("Exception: " + ex.getMessage() + "\n");
        StackTraceElement[] elements = ex.getStackTrace();
        for (int i = 0; i < elements.length; i++) {
            exceptionStr.append(elements[i].toString() + "\n");
        }
        return exceptionStr.toString();
    }
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:26,代碼來源:CrashHandler.java

示例3: 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

示例4: append

import java.text.DateFormat; //導入方法依賴的package包/類
@Override
public void append(LoggingEvent event) {
    boolean displayIsFine = display == null || display.isDisposed();
    boolean parentIsFine = parent == null || parent.isDisposed();
    if(displayIsFine || parentIsFine || text == null) {
        return;
    }
    DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL, locale);
    Date time = new Date(event.getTimeStamp());
    String dateTime = dateTimeFormat.format(time);
    String excMessage;
    Object message = event.getMessage();
    if (message instanceof String) {
        excMessage = (String) message;
    } else {
        return;
    }
    final String logMessage = String.format("[%s] %s%n", dateTime, excMessage);
    parent.getDisplay().asyncExec(() -> {
        if (!text.isDisposed()) {
            text.append(logMessage);
        }
    });
}
 
開發者ID:technology16,項目名稱:pgsqlblocks,代碼行數:25,代碼來源:UIAppender.java

示例5: rerun

import java.text.DateFormat; //導入方法依賴的package包/類
private void rerun(StatusBean bean) {

		try {
			final DateFormat format = DateFormat.getDateTimeInstance();
			boolean ok = MessageDialog.openQuestion(getViewSite().getShell(), "Confirm resubmission "+bean.getName(),
					  "Are you sure you want to rerun "+bean.getName()+" submitted on "+format.format(new Date(bean.getSubmissionTime()))+"?");

			if (!ok) return;

			final StatusBean copy = bean.getClass().newInstance();
			copy.merge(bean);
			copy.setUniqueId(UUID.randomUUID().toString());
			copy.setMessage("Rerun of "+bean.getName());
			copy.setStatus(org.eclipse.scanning.api.event.status.Status.SUBMITTED);
			copy.setPercentComplete(0.0);
			copy.setSubmissionTime(System.currentTimeMillis());

			queueConnection.submit(copy, true);

			reconnect();

		} catch (Exception e) {
			ErrorDialog.openError(getViewSite().getShell(), "Cannot rerun "+bean.getName(), "Cannot rerun "+bean.getName()+"\n\nPlease contact your support representative.",
					new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage()));
		}
	}
 
開發者ID:eclipse,項目名稱:scanning,代碼行數:27,代碼來源:StatusQueueView.java

示例6: run

import java.text.DateFormat; //導入方法依賴的package包/類
public void run() throws Exception {
  Date startTime = new Date();
  setUp();
  DateFormat formatter = DateFormat.getDateTimeInstance();
  System.out.println("Test started at: " + formatter.format(startTime));
  runQueries();
  printSummary();
  tearDown();
  Date endTime = new Date();
  System.out.println("Test ended at: " + formatter.format(endTime));
  long durationMs = endTime.getTime() - startTime.getTime();
  long durationS = durationMs / 1000;
  long durationM = durationS / 60;
  long durationMM = durationM % 60;
  long durationH = durationM / 60;
  System.out.println("Test took " + durationH + "hrs, " + durationMM + "min.");
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:18,代碼來源:PerfQuery.java

示例7: getDateTimeInstance

import java.text.DateFormat; //導入方法依賴的package包/類
/**
 * <p>Gets a date/time formatter instance using the specified style,
 * time zone and locale.</p>
 * 
 * @param dateStyle  date style: FULL, LONG, MEDIUM, or SHORT
 * @param timeStyle  time style: FULL, LONG, MEDIUM, or SHORT
 * @param timeZone  optional time zone, overrides time zone of
 *  formatted date
 * @param locale  optional locale, overrides system locale
 * @return a localized standard date/time formatter
 * @throws IllegalArgumentException if the Locale has no date/time
 *  pattern defined
 */
public static synchronized FastDateFormat getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone,
        Locale locale) {

    Object key = new Pair(new Integer(dateStyle), new Integer(timeStyle));
    if (timeZone != null) {
        key = new Pair(key, timeZone);
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    key = new Pair(key, locale);

    FastDateFormat format = (FastDateFormat) cDateTimeInstanceCache.get(key);
    if (format == null) {
        try {
            SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance(dateStyle, timeStyle,
                    locale);
            String pattern = formatter.toPattern();
            format = getInstance(pattern, timeZone, locale);
            cDateTimeInstanceCache.put(key, format);

        } catch (ClassCastException ex) {
            throw new IllegalArgumentException("No date time pattern for locale: " + locale);
        }
    }
    return format;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:41,代碼來源:FastDateFormat.java

示例8: getAudioFilename

import java.text.DateFormat; //導入方法依賴的package包/類
public File getAudioFilename() {
    // Get the directory for the user's public pictures directory.
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
    if(!dir.exists()) {
        if(!dir.mkdirs()) {
            Log.e(TAG, "Failed to create directory");
        }
    }

    Calendar c = Calendar.getInstance();
    DateFormat sdf = DateFormat.getDateTimeInstance();
    String filename = "voice_" + sdf.format(c.getTime());

    return new File(dir, filename + ".3gp");
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:16,代碼來源:AudioRecorderActivity.java

示例9: buildHistory

import java.text.DateFormat; //導入方法依賴的package包/類
/**
 * <p>Builds a text representation of the scanning history. Each scan is encoded on one
 * line, terminated by a line break (\r\n). The values in each line are comma-separated,
 * and double-quoted. Double-quotes within values are escaped with a sequence of two
 * double-quotes. The fields output are:</p>
 *
 * <ol>
 *  <li>Raw text</li>
 *  <li>Display text</li>
 *  <li>Format (e.g. QR_CODE)</li>
 *  <li>Unix timestamp (milliseconds since the epoch)</li>
 *  <li>Formatted version of timestamp</li>
 *  <li>Supplemental info (e.g. price info for a product barcode)</li>
 * </ol>
 */
CharSequence buildHistory() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getWritableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME,
                      COLUMNS,
                      null, null, null, null,
                      DBHelper.TIMESTAMP_COL + " DESC");

    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    StringBuilder historyText = new StringBuilder(1000);
    while (cursor.moveToNext()) {

      historyText.append('"').append(massageHistoryField(cursor.getString(0))).append("\",");
      historyText.append('"').append(massageHistoryField(cursor.getString(1))).append("\",");
      historyText.append('"').append(massageHistoryField(cursor.getString(2))).append("\",");
      historyText.append('"').append(massageHistoryField(cursor.getString(3))).append("\",");

      // Add timestamp again, formatted
      long timestamp = cursor.getLong(3);
      historyText.append('"').append(massageHistoryField(
          format.format(new Date(timestamp)))).append("\",");

      // Above we're preserving the old ordering of columns which had formatted data in position 5

      historyText.append('"').append(massageHistoryField(cursor.getString(4))).append("\"\r\n");
    }
    return historyText;
  } finally {
    close(cursor, db);
  }
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:50,代碼來源:HistoryManager.java

示例10: fill

import java.text.DateFormat; //導入方法依賴的package包/類
private void fill(File f) {
    File[]dirs = f.listFiles();
    this.setTitle("Current Dir: "+f.getName());
    List<Item>dir = new ArrayList<>();
    List<Item>fls = new ArrayList<>();
    try{
        for(File ff: dirs) {
            Date lastModDate = new Date(ff.lastModified());
            DateFormat formater = DateFormat.getDateTimeInstance();
            String date_modify = formater.format(lastModDate);
            if(ff.isDirectory()){
                File[] fbuf = ff.listFiles();
                int buf = 0;
                if(fbuf != null){
                    buf = fbuf.length;
                }
                else buf = 0;
                String num_item = String.valueOf(buf);
                if(buf == 0) num_item = num_item + " item";
                else num_item = num_item + " items";

                dir.add(new Item(ff.getName(),num_item,date_modify,ff.getAbsolutePath(),"directory_icon"));
            }
            else {
                fls.add(new Item(ff.getName(),ff.length() + " Byte", date_modify, ff.getAbsolutePath(),"file_icon"));
            }
        }
    }catch(Exception e) {
        System.out.println(e.toString());
    }

    Collections.sort(dir);
    Collections.sort(fls);
    dir.addAll(fls);
    if(!f.getName().equalsIgnoreCase("sdcard"))
        dir.add(0,new Item("..","Parent Directory","",f.getParent(),"directory_up"));
    adapter = new FileArrayAdapter(FileChooser.this, R.layout.activity_file_chooser,dir);
    this.setListAdapter(adapter);
}
 
開發者ID:yuvaraj119,項目名稱:WifiChatSharing,代碼行數:40,代碼來源:FileChooser.java

示例11: setCreatedAt

import java.text.DateFormat; //導入方法依賴的package包/類
@Override
protected void setCreatedAt(@Nullable Date createdAt) {
    if (createdAt != null) {
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT);
        timestampInfo.setText(dateFormat.format(createdAt));
    } else {
        timestampInfo.setText("");
    }
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:10,代碼來源:StatusDetailedViewHolder.java

示例12: testDoParseDate_Exception_WrongFormat

import java.text.DateFormat; //導入方法依賴的package包/類
public void testDoParseDate_Exception_WrongFormat() {
    DateFormat df = DateFormat.getDateTimeInstance();
    try {
        BaseLocalizer.doParseDate("8 30, 1988 11:25:59 AM", df);
        fail("This should not happen!");
    }
    catch (ParseException expected) {}
}
 
開發者ID:salesforce,項目名稱:grammaticus,代碼行數:9,代碼來源:GrammaticalLocalizerTest.java

示例13: MonitorsLabelProvider

import java.text.DateFormat; //導入方法依賴的package包/類
public MonitorsLabelProvider ( final IObservableMap... attributeMaps )
{
    super ();

    for ( int i = 0; i < attributeMaps.length; i++ )
    {
        attributeMaps[i].addMapChangeListener ( this.mapChangeListener );
    }
    this.attributeMaps = attributeMaps;

    this.dateFormat = DateFormat.getDateTimeInstance ( DateFormat.LONG, DateFormat.LONG );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:MonitorsLabelProvider.java

示例14: parse

import java.text.DateFormat; //導入方法依賴的package包/類
public static Date parse(String timestampStr, Locale locale, String timezone)
    throws ParseException {
  DateFormat dateFormat = null;
  if (locale != null) {
    dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
  } else {
    dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
  }
  if (timezone != null) {
    dateFormat.setTimeZone(TimeZone.getTimeZone(timezone));
  }
  return dateFormat.parse(timestampStr);
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:14,代碼來源:LocalDateUtil.java

示例15: advancedTest2

import java.text.DateFormat; //導入方法依賴的package包/類
@Test
public void advancedTest2() throws Exception {
    HtmlAdapter<PageListWithoutAnnotation> htmlAdapter = jspoon.adapter(PageListWithoutAnnotation.class);
    PageListWithoutAnnotation page = htmlAdapter.fromHtml(HTML_CONTENT);

    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, CUSTOM_DEFAULT_LOCALE);

    List<AnnotatedPost> posts = new ArrayList<>();
    posts.add(new AnnotatedPost(dateFormat.parse("Apr 11, 2017 11:20:00 AM"), "Header1", "Content1", "Tag1", "Tag3", "Tag4"));
    posts.add(new AnnotatedPost(dateFormat.parse("Apr 9, 2017 11:10:00 AM"), "Header2", "Content2", "Tag2", "Tag3", "Tag5"));
    posts.add(new AnnotatedPost(dateFormat.parse("Apr 1, 2017 9:37:00 PM"), "Header3", "Content3", "Tag1", "Tag4", "Tag7"));

    assertEquals(page.quote, "Blah, blah.");
    assertEquals(page.posts, posts);
}
 
開發者ID:DroidsOnRoids,項目名稱:jspoon,代碼行數:16,代碼來源:AdvancedTest.java


注:本文中的java.text.DateFormat.getDateTimeInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。