List of usage examples for org.joda.time LocalTime toString
public String toString(String pattern)
From source file:ca.ualberta.physics.cssdp.jaxb.LocalTimeAdapter.java
License:Apache License
public String marshal(LocalTime v) throws Exception { return v.toString("HH:mm"); }
From source file:cn.teamlab.wg.framework.struts2.tags.ExtDate.java
License:Apache License
public boolean end(Writer writer, String body) { String msg = null;//from ww w .jav a2 s . c om java.util.Date date = null; org.joda.time.DateTime dateTime = null; org.joda.time.LocalTime time = null; // find the name on the valueStack try { // suport Calendar also Object dateObject = findValue(name); if (dateObject instanceof org.joda.time.DateTime) { try { dateTime = (org.joda.time.DateTime) dateObject; } catch (Exception e) { LOG.error("Could not convert object with key '" + name + "' to a org.joda.time.DateTime instance"); // bad date, return a blank instead ? msg = ""; } } else if (dateObject instanceof org.joda.time.LocalTime) { try { time = (org.joda.time.LocalTime) dateObject; } catch (Exception e) { LOG.error("Could not convert object with key '" + name + "' to a org.joda.time.LocalTime instance"); // bad date, return a blank instead ? msg = ""; } } else { return super.end(writer, body); } } catch (Exception e) { LOG.error("Could not write out Date tag", e); } // try to find the format on the stack if (format != null) { format = findString(format); } else if (type != null) { format = ConfigurationUtil.getProperty(TYPE_PREFIX + type); } if (time != null) { if (format == null) { msg = time.toString(DateTimeFormat.forPattern(JODA_TIME_FORMAT_PATTERN)); } else { msg = time.toString(DateTimeFormat.forPattern(format)); } } if (dateTime != null) { TextProvider tp = findProviderInStack(); if (tp != null) { if (nice) { date = dateTime.toDate(); msg = formatTime(tp, date); } else { if (format == null) { String globalFormat = null; // if the format is not specified, fall back using the // defined property DATETAG_PROPERTY globalFormat = tp.getText(DATETAG_PROPERTY); // if tp.getText can not find the property then the // returned string is the same as input = // DATETAG_PROPERTY if (globalFormat != null && !DATETAG_PROPERTY.equals(globalFormat)) { msg = dateTime.toString(DateTimeFormat.forPattern(globalFormat)); } else { msg = dateTime.toString(DateTimeFormat.forPattern(JODA_DATE_FORMAT_PATTERN)); } } else { msg = dateTime.toString(DateTimeFormat.forPattern(format)); } } } } if (msg != null) { try { if (getVar() == null) { writer.write(msg); } else { putInContext(msg); } } catch (IOException e) { LOG.error("Could not write out Date tag", e); } } return super.end(writer, ""); }
From source file:com.codeabovelab.dm.cluman.ui.UiUtils.java
License:Apache License
public static String convertToStringFromJiffies(Long jiffies) { LocalTime timeOfDay = LocalTime.fromMillisOfDay(jiffies / 1000_000L); String time = timeOfDay.toString("HH:mm:ss"); return time;//from ww w. java2s. c o m }
From source file:com.kccomy.orgar.ui.editor.NodeEditorFragment.java
License:Apache License
@Override public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) { Calendar calendar = Calendar.getInstance(); calendar.set(0, 0, 0, hourOfDay, minute, second); LocalTime time = LocalTime.fromCalendarFields(calendar); scheduledTimeBtn.setText(time.toString(TIME_FORMAT)); scheduledTime = time;// w ww . j av a 2 s . c o m scheduledDate.withTime(time.getHourOfDay(), time.getMinuteOfHour(), 0, 0); }
From source file:com.metinkale.prayerapp.vakit.times.Times.java
License:Apache License
@NonNull private String adj(@NonNull String time, int t) { try {/*from w w w. ja va 2 s . c o m*/ double drift = getTZFix(); int[] adj = getMinuteAdj(); if ((drift == 0) && (adj[t] == 0)) { return time; } int h = (int) Math.round(drift - 0.5); int m = (int) ((drift - h) * 60); String[] s = time.split(":"); LocalTime lt = new LocalTime(Integer.parseInt(s[0]), Integer.parseInt(s[1]), 0); lt = lt.plusHours(h).plusMinutes(m).plusMinutes(adj[t]); time = lt.toString("HH:mm"); return time; } catch (Exception e) { Crashlytics.logException(e); return "00:00"; } }
From source file:com.metinkale.prayerapp.vakit.WidgetProviderClock.java
License:Apache License
public static void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, int widgetId) { if (mDP == 0) { Resources r = context.getResources(); mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()); }/*from www.j a v a 2s. c o m*/ Resources r = context.getResources(); SharedPreferences widgets = context.getSharedPreferences("widgets", 0); int w = widgets.getInt(widgetId + "_width", 500); int h = widgets.getInt(widgetId + "_height", 200); w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics()); h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics()); float scaleX = (float) w / (float) 5; float scaleY = (float) h / (float) 2; float scale = Math.min(scaleY, scaleX); w = (int) (5 * scale); h = (int) (2 * scale); if ((w <= 0) || (h <= 0)) { SharedPreferences.Editor edit = widgets.edit(); edit.remove(widgetId + "_width"); edit.remove(widgetId + "_height"); edit.apply(); updateAppWidget(context, appWidgetManager, widgetId); return; } Times times = null; long id = 0; try { id = widgets.getLong(widgetId + "", 0L); } catch (ClassCastException e) { widgets.edit().remove(widgetId + "").apply(); } if (id != 0) { times = Times.getTimes(id); } if (times == null) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_city_removed); Intent i = new Intent(context, WidgetConfigureClock.class); i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); remoteViews.setOnClickPendingIntent(R.id.image, PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); appWidgetManager.updateAppWidget(widgetId, remoteViews); return; } RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget_clock); remoteViews.setOnClickPendingIntent(R.id.abovePart, PendingIntent.getActivity(context, (int) System.currentTimeMillis(), new Intent(AlarmClock.ACTION_SHOW_ALARMS), PendingIntent.FLAG_UPDATE_CURRENT)); remoteViews.setOnClickPendingIntent(R.id.belowPart, Main.getPendingIntent(times)); Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); builder.appendPath(Long.toString(System.currentTimeMillis())); Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); remoteViews.setOnClickPendingIntent(R.id.center, PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT)); int next = times.getNext(); int last = next - 1; Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setDither(true); paint.setFilterBitmap(true); paint.setStyle(Style.FILL_AND_STROKE); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setShadowLayer(2, 2, 2, 0xFF555555); paint.setTextAlign(Align.CENTER); paint.setColor(Color.WHITE); LocalTime ltime = LocalTime.now(); paint.setTextSize(h * 0.55f); String time = ltime.toString("HH:mm"); if (Prefs.use12H()) { time = Utils.fixTime(time); String suffix = time.substring(time.indexOf(" ") + 1); time = time.substring(0, time.indexOf(" ")); canvas.drawText(time, (w / 2) - (paint.measureText(suffix) / 4), h * 0.4f, paint); paint.setTextSize(h * 0.275f); canvas.drawText(suffix, (w / 2) + paint.measureText(time), h * 0.2f, paint); } else { canvas.drawText(Utils.toArabicNrs(time), w / 2, h * 0.4f, paint); } LocalDate date = LocalDate.now(); String greg = Utils.format(date); String hicri = Utils.format(new HicriDate(date)); paint.setTextSize(h * 0.12f); float m = paint.measureText(greg + " " + hicri); if (m > (w * 0.8f)) { paint.setTextSize((h * 0.12f * w * 0.8f) / m); } paint.setTextAlign(Align.LEFT); canvas.drawText(greg, w * .1f, h * 0.55f, paint); paint.setTextAlign(Align.RIGHT); canvas.drawText(hicri, w * .9f, h * 0.55f, paint); remoteViews.setImageViewBitmap(R.id.widget, bmp); canvas.drawRect(w * 0.1f, h * 0.6f, w * 0.9f, h * 0.63f, paint); if (times.isKerahat()) { paint.setColor(0xffbf3f5b); } else { paint.setColor(Theme.Light.strokecolor); } canvas.drawRect(w * 0.1f, h * 0.6f, (w * 0.1f) + (w * 0.8f * times.getPassedPart()), h * 0.63f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.2f); paint.setTextAlign(Align.LEFT); if (Prefs.use12H()) { String l = Utils.fixTime(times.getTime(last)); String s = l.substring(l.indexOf(" ") + 1); l = l.substring(0, l.indexOf(" ")); canvas.drawText(l, w * 0.1f, h * 0.82f, paint); paint.setTextSize(h * 0.1f); canvas.drawText(s, (w * 0.1f) + (2 * paint.measureText(l)), h * 0.72f, paint); } else { canvas.drawText(Utils.fixTime(times.getTime(last)), w * 0.1f, h * 0.82f, paint); } paint.setTextSize(h * 0.12f); canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.1f, h * 0.95f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.2f); paint.setTextAlign(Align.RIGHT); if (Prefs.use12H()) { String l = Utils.fixTime(times.getTime(next)); String s = l.substring(l.indexOf(" ") + 1); l = l.substring(0, l.indexOf(" ")); canvas.drawText(l, (w * 0.9f) - (paint.measureText(s) / 2), h * 0.82f, paint); paint.setTextSize(h * 0.1f); canvas.drawText(s, w * 0.9f, h * 0.72f, paint); } else { canvas.drawText(Utils.fixTime(times.getTime(next)), w * 0.9f, h * 0.82f, paint); } paint.setTextSize(h * 0.12f); canvas.drawText(Vakit.getByIndex(next).getString(), w * 0.9f, h * 0.95f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.25f); paint.setTextAlign(Align.CENTER); paint.setFakeBoldText(true); canvas.drawText(times.getLeft(next, false), w * 0.5f, h * 0.9f, paint); paint.setFakeBoldText(false); try { appWidgetManager.updateAppWidget(widgetId, remoteViews); } catch (RuntimeException e) { if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) { Crashlytics.logException(e); } } }
From source file:com.mycompany.ajaxandxml.ws.LocalTimeAdapter.java
@Override public String marshal(LocalTime v) throws Exception { return v.toString("HH:mm:ss"); }
From source file:com.planyourexchange.utils.DateUtils.java
License:Open Source License
public static String toString(LocalTime localTime) { if (localTime != null) { return localTime.toString(PATTERN); }//ww w. ja v a 2s.co m return null; }
From source file:com.prayer.vakit.times.Times.java
License:Apache License
private String adj(String time, int t) { try {/*from w w w .j ava2 s. com*/ double drift = getTZFix(); int[] adj = getMinuteAdj(); if ((drift == 0) && (adj[t] == 0)) { return time; } int h = (int) Math.round(drift - 0.5); int m = (int) ((drift - h) * 60); String[] s = time.split(":"); LocalTime lt = new LocalTime(Integer.parseInt(s[0]), Integer.parseInt(s[1]), 0); lt = lt.plusHours(h).plusMinutes(m).plusMinutes(adj[t]); time = lt.toString("HH:mm"); return time; } catch (Exception e) { return "00:00"; } }
From source file:com.prayer.vakit.WidgetProviderClock.java
License:Apache License
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int widgetId) { if (mDP == 0) { Resources r = context.getResources(); mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()); }//from ww w. ja v a 2 s .c o m Resources r = context.getResources(); SharedPreferences widgets = context.getSharedPreferences("widgets", 0); int w = widgets.getInt(widgetId + "_width", 500); int h = widgets.getInt(widgetId + "_height", 200); w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics()); h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics()); float scaleX = (float) w / (float) 5; float scaleY = (float) h / (float) 2; float scale = Math.min(scaleY, scaleX); w = (int) (5 * scale); h = (int) (2 * scale); if ((w <= 0) || (h <= 0)) { SharedPreferences.Editor edit = widgets.edit(); edit.remove(widgetId + "_width"); edit.remove(widgetId + "_height"); edit.apply(); updateAppWidget(context, appWidgetManager, widgetId); return; } Times times = null; long id = 0; try { id = widgets.getLong(widgetId + "", 0L); } catch (ClassCastException e) { widgets.edit().remove(widgetId + "").apply(); } if (id != 0) { times = Times.getTimes(id); } if (times == null) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_city_removed_prayer); Intent i = new Intent(context, WidgetConfigureClock.class); i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); remoteViews.setOnClickPendingIntent(R.id.image, PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); appWidgetManager.updateAppWidget(widgetId, remoteViews); return; } RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget_clock_prayer); remoteViews.setOnClickPendingIntent(R.id.abovePart, PendingIntent.getActivity(context, (int) System.currentTimeMillis(), new Intent(AlarmClock.ACTION_SHOW_ALARMS), PendingIntent.FLAG_UPDATE_CURRENT)); remoteViews.setOnClickPendingIntent(R.id.belowPart, Main.getPendingIntent(times)); Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); builder.appendPath(Long.toString(System.currentTimeMillis())); Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); remoteViews.setOnClickPendingIntent(R.id.center, PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT)); int next = times.getNext(); int last = next - 1; Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setDither(true); paint.setFilterBitmap(true); paint.setStyle(Style.FILL_AND_STROKE); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setShadowLayer(2, 2, 2, 0xFF555555); paint.setTextAlign(Align.CENTER); paint.setColor(Color.WHITE); LocalTime ltime = LocalTime.now(); paint.setTextSize(h * 0.55f); String time = ltime.toString("HH:mm"); if (Prefs.use12H()) { time = Utils.fixTime(time); String suffix = time.substring(time.indexOf(" ") + 1); time = time.substring(0, time.indexOf(" ")); canvas.drawText(time, (w / 2) - (paint.measureText(suffix) / 4), h * 0.4f, paint); paint.setTextSize(h * 0.275f); canvas.drawText(suffix, (w / 2) + paint.measureText(time), h * 0.2f, paint); } else { canvas.drawText(Utils.toArabicNrs(time), w / 2, h * 0.4f, paint); } LocalDate date = LocalDate.now(); String greg = Utils.format(date); String hicri = Utils.format(new HicriDate(date)); paint.setTextSize(h * 0.12f); float m = paint.measureText(greg + " " + hicri); if (m > (w * 0.8f)) { paint.setTextSize((h * 0.12f * w * 0.8f) / m); } paint.setTextAlign(Align.LEFT); canvas.drawText(greg, w * .1f, h * 0.55f, paint); paint.setTextAlign(Align.RIGHT); canvas.drawText(hicri, w * .9f, h * 0.55f, paint); remoteViews.setImageViewBitmap(R.id.widget, bmp); canvas.drawRect(w * 0.1f, h * 0.6f, w * 0.9f, h * 0.63f, paint); if (times.isKerahat()) { paint.setColor(0xffbf3f5b); } else { paint.setColor(Theme.Light.strokecolor); } canvas.drawRect(w * 0.1f, h * 0.6f, (w * 0.1f) + (w * 0.8f * times.getPassedPart()), h * 0.63f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.2f); paint.setTextAlign(Align.LEFT); if (Prefs.use12H()) { String l = Utils.fixTime(times.getTime(last)); String s = l.substring(l.indexOf(" ") + 1); l = l.substring(0, l.indexOf(" ")); canvas.drawText(l, w * 0.1f, h * 0.82f, paint); paint.setTextSize(h * 0.1f); canvas.drawText(s, (w * 0.1f) + (2 * paint.measureText(l)), h * 0.72f, paint); } else { canvas.drawText(Utils.fixTime(times.getTime(last)), w * 0.1f, h * 0.82f, paint); } paint.setTextSize(h * 0.12f); canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.1f, h * 0.95f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.2f); paint.setTextAlign(Align.RIGHT); if (Prefs.use12H()) { String l = Utils.fixTime(times.getTime(next)); String s = l.substring(l.indexOf(" ") + 1); l = l.substring(0, l.indexOf(" ")); canvas.drawText(l, (w * 0.9f) - (paint.measureText(s) / 2), h * 0.82f, paint); paint.setTextSize(h * 0.1f); canvas.drawText(s, w * 0.9f, h * 0.72f, paint); } else { canvas.drawText(Utils.fixTime(times.getTime(next)), w * 0.9f, h * 0.82f, paint); } paint.setTextSize(h * 0.12f); canvas.drawText(Vakit.getByIndex(next).getString(), w * 0.9f, h * 0.95f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.25f); paint.setTextAlign(Align.CENTER); paint.setFakeBoldText(true); canvas.drawText(times.getLeft(next, false), w * 0.5f, h * 0.9f, paint); paint.setFakeBoldText(false); try { appWidgetManager.updateAppWidget(widgetId, remoteViews); } catch (RuntimeException e) { if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) { } } }