Java Code Examples for java.util.Date.toString()

The following are Jave code examples for showing how to use toString() of the java.util.Date class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dataset-lib   File: StringIndex.java   View Source Code Vote up 6 votes
public void backup(String name, String path,String indexName) {
    if(storageProviderPath!=null){
        try{
        Socket socket=new Socket(storageProviderPath, storageProviderPort);
        PrintWriter writer=new PrintWriter(socket.getOutputStream(), true);
        ObjectOutputStream serializableOutputStream=new ObjectOutputStream(socket.getOutputStream());
        Date d=new Date();
        String timestamp=d.toString();
        writer.write("put:"+indexName);
        serializableOutputStream.writeObject(this);
        }catch(UnknownHostException uhe){
            uhe.printStackTrace();
        }
    }
    else{
        try {
        FileOutputStream fs = new FileOutputStream(path + "/" + name + ".ser");
        ObjectOutputStream out = new ObjectOutputStream(fs);
        out.writeObject(this);
        out.close();
        fs.close();
        } catch (IOException e) {
        //TODO: handle exception
        }
    }
}
 
Example 2
Project: monarch   File: LogWriterImpl.java   View Source Code Vote up 6 votes
/**
 * Convert a Date to a timestamp String.
 * 
 * @param d a Date to format as a timestamp String.
 * @return a String representation of the current time.
 */
protected String formatDate(Date d) {
  try {
    synchronized (timeFormatter) {
      // Need sync: see bug 21858
      return timeFormatter.format(d);
    }
  } catch (Exception e1) {
    // Fix bug 21857
    try {
      return d.toString();
    } catch (Exception e2) {
      try {
        return Long.toString(d.getTime());
      } catch (Exception e3) {
        return "timestampFormatFailed";
      }
    }
  }
}
 
Example 3
Project: neoscada   File: ChangeEntryItemProvider.java   View Source Code Vote up 6 votes
/**
 * This returns the label styled text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Object getStyledText ( Object object )
{
    Date labelValue = ( (ChangeEntry)object ).getDate ();
    String label = labelValue == null ? null : labelValue.toString ();
    StyledString styledLabel = new StyledString ();
    if ( label == null || label.length () == 0 )
    {
        styledLabel.append ( getString ( "_UI_ChangeEntry_type" ), StyledString.Style.QUALIFIER_STYLER ); //$NON-NLS-1$
    }
    else
    {
        styledLabel.append ( getString ( "_UI_ChangeEntry_type" ), StyledString.Style.QUALIFIER_STYLER ).append ( " " + label ); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return styledLabel;
}
 
Example 4
Project: parabuild-ci   File: CVS.java   View Source Code Vote up 5 votes
/**
 * <p>Convert a CVS date string into local time.</p>
 *
 * @param cvsDate The CVS date string.
 *
 * @return The date, converted to local time and reformatted.
 */
public String localTime (String cvsDate) {
  // A cvsDate has the following form "$Date: 2016/12/14 $"
  if (!cvsDate.startsWith("$Date: ")) {
    return cvsDate;
  }

  String yrS = cvsDate.substring(7,11);
  String moS = cvsDate.substring(12,14);
  String daS = cvsDate.substring(15,17);
  String hrS = cvsDate.substring(18,20);
  String miS = cvsDate.substring(21,23);
  String seS = cvsDate.substring(24,26);

  TimeZone tz = TimeZone.getTimeZone("GMT+0");
  GregorianCalendar gmtCal = new GregorianCalendar(tz);

  try {
    gmtCal.set(Integer.parseInt(yrS),
 Integer.parseInt(moS)-1,
 Integer.parseInt(daS),
 Integer.parseInt(hrS),
 Integer.parseInt(miS),
 Integer.parseInt(seS));
  } catch (NumberFormatException e) {
    // nop
  }

  Date d = gmtCal.getTime();

  return d.toString();
}
 
Example 5
Project: rapidminer   File: Evaluation.java   View Source Code Vote up 5 votes
/**
 * Converts the input to a string with special missing value handling
 */
private String dateToString(Date input) {
	if (input == null) {
		return null;
	} else {
		return input.toString();
	}
}
 
Example 6
Project: LP_Proyecto   File: Principal.java   View Source Code Vote up 5 votes
public void ReconocedorMensaje(JTextArea TextAreaActual) {
    Palabra = GPalabra.getGst();
    if (!"".equals(Palabra)) {
        int answer = JOptionPane.showConfirmDialog(jd_User, "¿Quisiste decir " + Palabra + "?");
        if (answer == JOptionPane.YES_OPTION && Palabra.equals("send")) {
            String Mensaje = TextAreaActual.getText();
            Date FechaActual = new Date();
            String Destinatario = ((Contacto) cb_Recipients_Inbox.getSelectedItem()).getName() + " " + ((Contacto) cb_Recipients_Inbox.getSelectedItem()).getPhone();

            Mensaje NuevoMensaje = new Mensaje(FechaActual.toString(), Mensaje, Destinatario, UsuarioIngresado.getUserName(), true);
            ListaMensajes.add(NuevoMensaje);
            InsertarMensajeEnDB(FechaActual.toString(), Mensaje, Destinatario, UsuarioIngresado.getUserName());

            TextAreaActual.setText("");
            LlenarInbox();

            ListaBitacoras.add(new Bitacora(FechaBitacora.toString(), "Envio un mensaje", UsuarioIngresado.getUserName()));
            InsertarBitacoraEnDB(FechaBitacora.toString(), "Envio un mensaje", UsuarioIngresado.getUserName());
            LlenarBitacora();

            JOptionPane.showMessageDialog(jd_User, "Mensaje enviado exitosamente", "OPERACION EXITOSA", JOptionPane.INFORMATION_MESSAGE);
            Palabra = "";
            PalabraAnterior = "";
            GPalabra.setGst("");
        } else {
            Palabra = "";
            PalabraAnterior = "";
            GPalabra.setGst("");
        }
    }
}
 
Example 7
Project: elegant-springboot   File: TimeProvider.java   View Source Code Vote up 5 votes
@PostMapping("current_time")
public TimeResponse currentTime(@RequestBody TimeRequest timeRequest) {
    String name = timeRequest.getName();
    Date date = new Date();
    logger.info("get request : {}", timeRequest.getName());
    return new TimeResponse(name, date.toString(), date.getTime());
}
 
Example 8
Project: TestDemo1-github   File: CTool.java   View Source Code Vote up 5 votes
/**
 *null 处理
 *@param d 要进行转换的日期对像
 *@return 如果d为null值,返回空串"",否则返回d.toString()
 */

public static String null2Blank(Date d) {
    if (d == null)
        return "";
    else
        return d.toString();
}
 
Example 9
Project: oscm   File: BLValidator.java   View Source Code Vote up 5 votes
/**
 * Checks the date range given with the input parameters.
 * 
 * @param fromDate
 *            the value validation is being performed on.
 * @param toDate
 *            the value validation is being performed on.
 * @throws ValidationException
 */
public static void isValidDateRange(Date fromDate, Date toDate)
        throws ValidationException {
    if (fromDate.after(toDate)) {
        Object[] params = { "From: " + fromDate.toString(),
                "To: " + toDate.toString() };
        ValidationException vf = new ValidationException(
                ReasonEnum.INVALID_DATE_RANGE, null, params);
        logValidationFailure(vf);
        throw vf;
    }
}
 
Example 10
Project: parabuild-ci   File: CVS.java   View Source Code Vote up 5 votes
/**
 * <p>Convert a CVS date string into local time.</p>
 *
 * @param cvsDate The CVS date string.
 *
 * @return The date, converted to local time and reformatted.
 */
public static String localTime (String cvsDate) {
  // A cvsDate has the following form "$Date: 2016/12/14 $"
  if (!cvsDate.startsWith("$Date: ")) {
    return cvsDate;
  }

  String yrS = cvsDate.substring(7,11);
  String moS = cvsDate.substring(12,14);
  String daS = cvsDate.substring(15,17);
  String hrS = cvsDate.substring(18,20);
  String miS = cvsDate.substring(21,23);
  String seS = cvsDate.substring(24,26);

  TimeZone tz = TimeZone.getTimeZone("GMT+0");
  GregorianCalendar gmtCal = new GregorianCalendar(tz);

  try {
    gmtCal.set(Integer.parseInt(yrS),
 Integer.parseInt(moS)-1,
 Integer.parseInt(daS),
 Integer.parseInt(hrS),
 Integer.parseInt(miS),
 Integer.parseInt(seS));
  } catch (NumberFormatException e) {
    // nop
  }

  Date d = gmtCal.getTime();

  return d.toString();
}
 
Example 11
Project: firebase-admin-java   File: DefaultLogger.java   View Source Code Vote up 4 votes
protected String buildLogMessage(Level level, String tag, String message, long msTimestamp) {
  Date now = new Date(msTimestamp);
  return now.toString() + " " + "[" + level + "] " + tag + ": " + message;
}
 
Example 12
Project: incubator-netbeans   File: MirrorValuesApp.java   View Source Code Vote up 4 votes
private void mirrors() {
    boolean boo = true;
    byte b = 5;
    char c = 'c';
    short s = 512;
    int i = 10000;
    long l = Long.MAX_VALUE;
    float f = 12.12f;
    double d = 1e150;
    
    int[] iarr = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    double[][] darr = new double[][] { { 0.1, 0.2, 0.3 }, { 1.1, 1.2, 1.3 }, { 2.1, 2.2, 2.3 } };
    
    String str = "A String";
    Integer integer = new Integer(Integer.MIN_VALUE);
    
    Date date = new Date(1000000000l);
    date.toString(); // This is necessary to initialize the Date.cdate field and Gregorian$Date class.
    Color color = Color.RED;
    Point point = new Point(10, 10);
    File file = new File("/tmp/Foo.txt");
    URL url = createURL("http://netbeans.org");
    URL url2 = createPristineURL();
    
    Color[][] colors = new Color[][] { { Color.WHITE, Color.BLACK }, { Color.YELLOW, Color.GRAY } };
    
    List selfReferencedList = createSelfReferencedList();
    EventObject event = createObjectCircle();
    
    System.currentTimeMillis();             // LBREAKPOINT
    
    boolean newValues = (boo == false) && b == (byte) 255 && c == 'Z' &&
                         s == (short) -1024 && i == -1 && l == 123456789101112l &&
                         f == 2e-2f && d == -3e250 &&
                         Arrays.equals(iarr, new int[] { 9, 7, 5, 3, 1 }) &&
                         Arrays.deepEquals(darr, new double[][] { { 1e100, 2e200 }, { 1.1e100, 2.1e200 }, { 1.2e100, 2.2e200 }, { 1.3e100, 2.3e200 } }) &&
                         str.equals("An alternate sTRING") &&
                         integer.equals(-1048576) &&
                         date.equals(new Date(3333333333l)) &&
                         color.equals(Color.GREEN) &&
                         point.equals(new Point(-100, -100)) &&
                         file.equals(new File("/tmp/Test.java")) &&
                         url.equals(createURL("http://debugger.netbeans.org")) &&
                         url2 == null;
    
    System.currentTimeMillis();             // LBREAKPOINT
}
 
Example 13
Project: thornsec-core   File: NetworkModel.java   View Source Code Vote up 4 votes
private ManageExec getManageExec(String server, String action, OutputStream out, boolean quiet) {
	// need to do a series of local checks eg known_hosts or expected
	// fingerprint
	if (servers.containsKey(server)) {
		ServerModel serverModel = servers.get(server);
		PasswordExec pass = new PasswordExec(server, this);

		if (!pass.init()) {
			return null;
		} else {
			String password = pass.getPassword();
			
			System.out.println("PASS: password in keychain for " + serverModel.getLabel());
			String audit = getScript(serverModel, action, quiet);
			
			if (action.equals("dryrun")) {
				try {
					Date now = new Date();
					PrintWriter wr = new PrintWriter(new FileOutputStream("./" + server + "_" + now.toString() + ".sh"));
					wr.write(audit);
					wr.flush();
					wr.close();
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return null;
			}

			if (password == null || password.equals("")) {
				System.out.println("FAIL: no password in keychain for " + serverModel.getLabel());
				return null;
			}
			
			ManageExec exec = new ManageExec(server, this, password, audit, out);
			return exec;
		}
	} else {
		System.out.println("No server " + server);
	}
	return null;
}
 
Example 14
Project: keepass2android   File: SftpATTRS.java   View Source Code Vote up 4 votes
public String  getMtimeString(){
  Date date= new Date(((long)mtime)*1000);
  return (date.toString());
}
 
Example 15
Project: aos-FileCoreLibrary   File: SftpATTRS.java   View Source Code Vote up 4 votes
public String  getAtimeString(){
  Date date= new Date(((long)atime)*1000L);
  return (date.toString());
}
 
Example 16
Project: aos-FileCoreLibrary   File: SftpATTRS.java   View Source Code Vote up 4 votes
public String  getMtimeString(){
  Date date= new Date(((long)mtime)*1000L);
  return (date.toString());
}
 
Example 17
Project: CodeCompilerApp   File: FileInfoDialog.java   View Source Code Vote up 4 votes
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    View view = new DialogHelper.Builder(getActivity())
            .setTitle(R.string.info)
            .setView(R.layout.dialog_fragment_file_info)
            .createSkeletonView();
    //final View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_fragment_file_info, null);

    ListView list = (ListView) view.findViewById(android.R.id.list);

    DocumentFile file = DocumentFile.fromFile(new File(AccessStorageApi.getPath(getActivity(), (Uri) getArguments().getParcelable("uri"))));

    if (file == null && Device.hasKitKatApi()) {
        file = DocumentFile.fromSingleUri(getActivity(), (Uri) getArguments().getParcelable("uri"));
    }

    // Get the last modification information.
    Long lastModified = file.lastModified();

    // Create a new date object and pass last modified information
    // to the date object.
    Date date = new Date(lastModified);

    String[] lines1 = {
            getString(R.string.name),
            //getString(R.string.folder),
            getString(R.string.size),
            getString(R.string.modification_date)
    };
    String[] lines2 = {
            file.getName(),
            //file.getParent(),
            FileUtils.byteCountToDisplaySize(file.length()),
            date.toString()
    };

    list.setAdapter(new AdapterTwoItem(getActivity(), lines1, lines2));


    return new AlertDialog.Builder(getActivity())
            .setView(view)
            .setPositiveButton(android.R.string.ok,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }
            )
            .create();
}
 
Example 18
Project: hadoop   File: OracleDateSplitter.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
protected String dateToString(Date d) {
  // Oracle Data objects are always actually Timestamps
  return "TO_TIMESTAMP('" + d.toString() + "', 'YYYY-MM-DD HH24:MI:SS.FF')";
}
 
Example 19
Project: DBPA   File: Post.java   View Source Code Vote up 4 votes
public void setDate(Date date) {
    this.date = date;
    this.dateString = date.toString();
}
 
Example 20
Project: Open-DM   File: Retention.java   View Source Code Vote up 3 votes
/**
 * Use this constructor to create a retention object from hcp which has a retention class
 * 
 * @param className:
 *            retention class name
 * @param hcapValue:
 *            c+class name
 * @param date:
 *            date the object will expire
 */
protected Retention(String className,
        String hcapValue,
        Date date) {
    this.type = Type.RETENTION_CLASS;
    this.hcapValue = hcapValue;
    this.uiValue = date.toString();
    this.className = className;
}