List of usage examples for java.text DateFormat getTimeInstance
public static final DateFormat getTimeInstance(int style)
From source file:Main.java
public static void main(String[] argv) throws Exception { DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG); String s = dateFormat.format(new Date()); System.out.println(dateFormat.getNumberFormat().getMinimumFractionDigits()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG); String s = dateFormat.format(new Date()); System.out.println(s);//from ww w. jav a2 s .c o m }
From source file:DateFormatDemo.java
public static void main(String args[]) { Date date = new Date(); DateFormat df = DateFormat.getTimeInstance(DateFormat.LONG); System.out.println("Long form: " + df.format(date)); }
From source file:DateFormatDemo.java
public static void main(String args[]) { Date date = new Date(); DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); System.out.println("Short form: " + df.format(date)); }
From source file:TimeUtil.java
public static String windowFormat(long msecs) { Date tDate = new Date(msecs); long now = System.currentTimeMillis(); long diff = now - msecs; // start with the last 24 hours long comp = MS_PER_DAY; // start comparing if (diff < comp) { // it's within the last 24 hours - just return the time DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT); return formatter.format(tDate); }//from w ww . j a v a 2 s.c o m // now expand to another day comp += MS_PER_DAY; if (diff < comp) { // it's within the last 48 hours - just return the time DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT); return "Yesterday " + formatter.format(tDate); } // now up it to a week comp += 5 * MS_PER_DAY; if (diff < comp) { // return the day of the week and the time // get time to be formatted into a calendar GregorianCalendar tCal = new GregorianCalendar(); tCal.setTime(tDate); SimpleDateFormat formatter = new SimpleDateFormat("EEEE"); return formatter.format(tDate); } // just return full date DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); return formatter.format(tDate); }
From source file:proyectoprestamos.DatosUsuario.java
/** * Creates new form DatosUsuario/* ww w. j ava 2 s. c o m*/ */ public DatosUsuario() { initComponents(); Calendar cal = Calendar.getInstance(); DateFormat formateadorFechaLarga = DateFormat.getDateInstance(DateFormat.MEDIUM); System.out.println(formateadorFechaLarga.format(cal.getTime())); jLabelFecha2.setText(String.valueOf(formateadorFechaLarga.format(cal.getTime()))); DateFormat formateadorHoraCorta = DateFormat.getTimeInstance(DateFormat.SHORT); System.out.println(formateadorHoraCorta.format(cal.getTime())); jLabelHora2.setText(String.valueOf(formateadorHoraCorta.format(cal.getTime()))); setLocationRelativeTo(null); setIconImage(new ImageIcon(getClass().getResource("/imagenes/p.png")).getImage()); }
From source file:TimeViewer.java
protected void refreshTable() { int style = DateFormat.SHORT; DateFormat parser = DateFormat.getTimeInstance(style); selectedDate = new Date(); tableModel.fireTableDataChanged();/*from w w w . j a va 2 s . co m*/ }
From source file:ClockDemo.java
/** * The init method is called when the browser first starts the applet. It * sets up the Label component and obtains a DateFormat object */// w ww . j a va 2 s. c o m public void init() { time = new Label(); time.setFont(new Font("helvetica", Font.BOLD, 12)); time.setAlignment(Label.CENTER); setLayout(new BorderLayout()); add(time, BorderLayout.CENTER); timeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM); }
From source file:com.sun.utils.StatusFragment.java
public void addMessage(String message) { DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT); message = format.format(new Date()) + " - " + message; messages.add(message);/*w ww. j a va 2 s.c o m*/ while (messages.size() > LIMIT) { messages.removeFirst(); } notifyAdapters(); }
From source file:com.oldsneerjaw.sleeptimer.CountdownNotifierTest.java
@Override protected void setUp() throws Exception { super.setUp(); Context mockContext = Mockito.mock(Context.class); Mockito.when(mockContext.getPackageName()).thenReturn("com.oldsneerjaw.sleeptimer"); Mockito.when(mockContext.getApplicationContext()).thenReturn(mockContext); mockNotificationManager = Mockito.mock(NotificationManager.class); Resources mockResources = Mockito.mock(Resources.class); Mockito.when(mockResources.getString(R.string.countdown_notification_title)).thenReturn(NOTIFICATION_TITLE); Mockito.when(mockResources.getString(R.string.countdown_notification_text)).thenReturn(NOTIFICATION_TEXT); mockCountdownTimeFormatFactory = Mockito.mock(CountdownNotifier.TimeFormatFactory.class); Mockito.when(mockCountdownTimeFormatFactory.getTimeFormat()) .thenReturn(DateFormat.getTimeInstance(DateFormat.SHORT)); notifier = new CountdownNotifier(mockContext, mockNotificationManager, mockResources, mockCountdownTimeFormatFactory); }