java.util.Date.toLocaleString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中java.util.Date.toLocaleString()方法的一些代码示例,展示了Date.toLocaleString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.toLocaleString()方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:toLocaleString

Date.toLocaleString介绍

[英]Returns the string representation of this Date for the default Locale.
[中]返回默认区域设置的此日期的字符串表示形式。

代码示例

代码示例来源:origin: guardianproject/haven

@Override
public void onBindViewHolder(EventVH holder, int position) {
  Event event = events.get(position);
  String title = event.getStartTime().toLocaleString();
  String desc = event.getEventTriggers().size() + " " + context.getString(R.string.detection_events);
  holder.title.setText(title);
  holder.note.setText(desc);
}

代码示例来源:origin: guardianproject/haven

private void showEvents(StringBuffer page)
{
  page.append("<h1>Events</h1><hr/>\n");
  List<Event> events = Event.listAll(Event.class);
  for (Event event: events)
  {
    String title = event.getStartTime().toLocaleString();
    String desc = event.getEventTriggers().size() + " triggered events";
    page.append("<b>").append("<a href=\"/event/").append(event.getId()).append("\">");
    page.append(title).append("</a></b><br/>");
    page.append(desc);
    page.append("<hr/>");
  }
}

代码示例来源:origin: guardianproject/haven

private String generateLog () {
  StringBuilder mEventLog = new StringBuilder();
  setTitle("Event @ " + mEvent.getStartTime().toLocaleString());
  for (EventTrigger eventTrigger : mEvent.getEventTriggers()) {
    mEventLog.append("Event Triggered @ ").append(
         new SimpleDateFormat(Utils.DATE_TIME_PATTERN,
            Locale.getDefault()).format(eventTrigger.getTriggerTime())).append("\n");
    String sType = eventTrigger.getStringType(this);
    mEventLog.append("Event Type: ").append(sType);
    mEventLog.append("\n==========================\n");
  }
  return mEventLog.toString();
}

代码示例来源:origin: guardianproject/haven

private void showEvent (Event event, StringBuffer page) {
  List<EventTrigger> triggers = event.getEventTriggers();
  page.append("<h1>Event: ").append(event.getStartTime().toLocaleString()).append("</h1><hr/>\n");
  for (EventTrigger eventTrigger: triggers)
  {
    String title = eventTrigger.getStringType(mContext);
    String desc = new SimpleDateFormat(Utils.DATE_TIME_PATTERN,
        Locale.getDefault()).format(eventTrigger.getTriggerTime());
    page.append("<b>");
    page.append(title).append("</b><br/>");
    page.append(desc).append("<br/>");
    String mediaPath = "/event/" + event.getId() + "/trigger/" + eventTrigger.getId();
    if (eventTrigger.getType() == EventTrigger.CAMERA)
    {
      page.append("<img src=\"").append(mediaPath).append("\" width=\"100%\"/>");
      page.append("<a href=\"").append(mediaPath).append("\">Download Media").append("</a>");
    }
    else if (eventTrigger.getType() == EventTrigger.MICROPHONE)
    {
      page.append("<audio src=\"").append(mediaPath).append("\"></audio>");
      page.append("<a href=\"").append(mediaPath).append("\">Download Media").append("</a>");
    }
    page.append("<hr/>");
  }
}

代码示例来源:origin: guardianproject/haven

private void shareEvent ()
{
  String title = "Phoneypot: " + mEvent.getStartTime().toLocaleString();
  //need to "send multiple" to get more than one attachment
  final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
  emailIntent.setType("text/plain");
  emailIntent.putExtra(Intent.EXTRA_SUBJECT, title);
  emailIntent.putExtra(Intent.EXTRA_TEXT, generateLog());
  //has to be an ArrayList
  ArrayList<Uri> uris = new ArrayList<>();
  //convert from paths to Android friendly Parcelable Uri's
  for (EventTrigger trigger : mEvent.getEventTriggers())
  {
    // ignore triggers for which we do not have valid file/file-paths
    if (trigger.getMimeType() == null || trigger.getPath() == null)
      continue;
    File fileIn = new File(trigger.getPath());
    Uri u = Uri.fromFile(fileIn);
    uris.add(u);
  }
  emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
  startActivity(Intent.createChooser(emailIntent, getString(R.string.share_event_action)));
}

代码示例来源:origin: guardianproject/haven

String desc = eventTrigger.getTriggerTime().toLocaleString();

代码示例来源:origin: pedrovgs/Renderers

private void renderDate() {
  String now = new Date().toLocaleString();
  date.setText(now);
 }
}

代码示例来源:origin: guardianproject/haven

mRecyclerView = findViewById(R.id.event_trigger_list);
setTitle(mEvent.getStartTime().toLocaleString());

代码示例来源:origin: hengyunabc/xdiamond

/**
 * 得到Properties格式的字符串,并没有对Unicode字符做转义处理
 * 
 * @return
 */
@SuppressWarnings("deprecation")
public String toUTF8PropertiesString() {
 StringBuilder sb = new StringBuilder(512);
 if (description != null) {
  sb.append("# description:").append(description).append("\r\n");
 }
 sb.append("# id:").append(id).append("\r\n");
 sb.append("# version:").append(version).append("\r\n");
 if (createDate != null) {
  sb.append("# createDate:").append(createDate.toLocaleString()).append("\r\n");
 }
 if (updateDate != null) {
  sb.append("# updateDate:").append(updateDate.toLocaleString()).append("\r\n");
 }
 // if (dependencyInfo != null) {
 // sb.append("# dependencyInfo:").append(dependencyInfo).append("\r\n");
 // }
 sb.append(key).append('=').append(value).append("\r\n");
 return Native2ascii.encode(sb.toString());
}

代码示例来源:origin: stackoverflow.com

Log.d(TAG, "periodic notification " + d.toLocaleString() + " mili " + d.getTime());
recorder.read(audioData, 0, finalBufferSize);

代码示例来源:origin: stackoverflow.com

public String getCurrDate()
{
  String dt;
  Date cal = Calendar.getInstance().getTime();
  dt = cal.toLocaleString();
  return dt;
}

代码示例来源:origin: hengyunabc/zpush

public String toString() {
  StringBuilder sb = new StringBuilder(512);
  return sb.append("{expiration:")
      .append(expiration.toLocaleString())
      .append(",token:")
      .append(Hex.encodeHexString(token)).toString();
  // return JSON.toJSONString(this);
}

代码示例来源:origin: stackoverflow.com

String DATE_FORMAT_NOW = "yyyy/MM/dd";
 Calendar cal = Calendar.getInstance();
 Date date = null;
 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
 String dateInStringFormat = sdf.format(cal.getTime());
 try {
   //parsing the date string with format "yyyy/MM/dd"
   date = sdf.parse(dateInStringFormat);
   System.out.println(date.toLocaleString());
 } catch (ParseException ex) {
   Logger.getLogger(DateTest.class.getName()).log(Level.SEVERE, null, ex);
 }

代码示例来源:origin: stackoverflow.com

Long longDate = Long.valueOf(date);

Calendar cal = Calendar.getInstance();
int offset = cal.getTimeZone().getOffset(cal.getTimeInMillis());
Date da = new Date(); 
da = new Date(longDate-(long)offset);
cal.setTime(da);

String time =cal.getTime().toLocaleString(); 
//this is full string        

time = DateFormat.getTimeInstance(DateFormat.MEDIUM).format(da);
//this is only time

time = DateFormat.getDateInstance(DateFormat.MEDIUM).format(da);
//this is only date

代码示例来源:origin: NightscoutFoundation/xDrip

public boolean WriteDebugDataToMongo(String message)
{
  String complete = machineName_ + " " + new Date().toLocaleString() + " " + message;
  BasicDBObject doc = new BasicDBObject("DebugMessage", complete);
  return WriteToMongo(doc);
}

代码示例来源:origin: io.leopard/myjetty-workbench

@Override
public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
  String html = "当前服务器IP:127.0.0.1  服务启动:" + serverStartTime.toLocaleString();
  env.getOut().write(html);
}

代码示例来源:origin: io.leopard.topnb/topnb-web

@Override
public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
  String html = "当前服务器IP:127.0.0.1  服务启动:" + serverStartTime.toLocaleString();
  env.getOut().write(html);
}

代码示例来源:origin: stackoverflow.com

private void setRecurringAlarm(Context context) {
  Calendar updateTime = Calendar.getInstance();
  updateTime.setTimeZone(TimeZone.getDefault());
  updateTime.set(Calendar.HOUR_OF_DAY, 12);
  updateTime.set(Calendar.MINUTE, 30);
  Intent downloader = new Intent(context, BroadcastReceiverService.class);
  downloader.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  pendingIntent = PendingIntent.getBroadcast(context, 0, downloader, PendingIntent.FLAG_CANCEL_CURRENT);
  AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(),  30 * 1000/*AlarmManager.INTERVAL_FIFTEEN_MINUTES*/, pendingIntent);

  Log.d("MyActivity", "Set alarmManager.setRepeating to: " + updateTime.getTime().toLocaleString());
}

代码示例来源:origin: org.mobicents.smsc/smpp-simulator

public synchronized void addMessage(String msg, String info) {
  
  Date d1 = new Date();
  String s1 = d1.toLocaleString();
  Vector newRow = new Vector();
  newRow.add(s1);
  newRow.add(msg);
  newRow.add(info);
  model.getDataVector().add(0,newRow);
  model.newRowsAdded(new TableModelEvent(model));
}

代码示例来源:origin: com.quhaodian.discover/discover-website

public static void main(String[] args) {
  DateConver conver = getDefault();
  System.out.println(conver.conver("2018/11").toLocaleString());
 }
}

相关文章