Java Code Examples for org.joda.time.DateTime#toString()

The following examples show how to use org.joda.time.DateTime#toString() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sakai   File: TimeUtil.java    License: Educational Community License v2.0 6 votes vote down vote up
public String getDateTimeWithTimezoneConversion(Date dateToConvert) {
    if (dateToConvert == null) {
        return null;
    }
    DateTime dt = new DateTime(dateToConvert);
    DateTimeFormatter fmt = ISODateTimeFormat.yearMonthDay();
    DateTimeFormatter fmtTime = ISODateTimeFormat.hourMinuteSecond();

    // If the client browser is in a different timezone than server, need to modify date
    if (m_client_timezone !=null && m_server_timezone!=null && !m_client_timezone.hasSameRules(m_server_timezone)) {
      DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(m_client_timezone);
      fmt = fmt.withZone(dateTimeZone);
      fmtTime = fmtTime.withZone(dateTimeZone);
    }
    return dt.toString(fmt) + " " + dt.toString(fmtTime);
}
 
Example 2
private void checkStateDate(DateTime stateDate, final PhdProcessStateType type) {
    Collection<? extends PhdProcessState> orderedStates = getProcess().getOrderedStates();

    for (PhdProcessState phdProcessState : orderedStates) {
        if (phdProcessState == this) {
            continue;
        }

        if (phdProcessState.getStateDate() != null && phdProcessState.getStateDate().isAfter(stateDate)) {
            String newStateDate = stateDate.toString("dd/MM/yyyy") + " - " + type.getLocalizedName();
            String actualStateDate =
                    phdProcessState.getStateDate().toString("dd/MM/yyyy") + " - "
                            + phdProcessState.getType().getLocalizedName();

            throw new PhdDomainOperationException("error.PhdProcessState.state.date.is.previous.of.actual.state.on.process",
                    newStateDate, actualStateDate);
        }
    }
}
 
Example 3
Source Project: tablestore-examples   File: ReadData.java    License: Apache License 2.0 5 votes vote down vote up
private static void printRow(Row row) {
    long ts = row.getPrimaryKey().getPrimaryKeyColumn("ts").getValue().asLong();
    DateTime dateTime = new DateTime(ts * 1000);
    String timeStr = dateTime.toString("yyyy/MM/dd HH:mm:ss");
    System.out.println(timeStr +
            ", Price:" + row.getColumn("price").get(0).getValue().asDouble() +
            ", Count:" + row.getColumn("ordercount").get(0).getValue().asLong());
}
 
Example 4
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("File signature: ").append(signature).append("\n");
    sb.append("File source ID: ").append(fileSourceId).append("\n");
    sb.append("Project ID - data 1: ").append(projectIdGuidData1).append("\n");
    sb.append("Project ID - data 2: ").append(projectIdGuidData2).append("\n");
    sb.append("Project ID - data 3: ").append(projectIdGuidData3).append("\n");
    sb.append("Project ID - data 4: ").append(projectIdGuidData4).append("\n");
    sb.append("Version: ").append(versionMajor).append(".").append(versionMinor).append("\n");
    sb.append("System identifier: ").append(systemIdentifier).append("\n");
    sb.append("Generating software: ").append(generatingSoftware).append("\n");
    if (dayOfYear != 0 && year != 0) {
        DateTime dateTime = new DateTime();
        dateTime = dateTime.withYear(year).withDayOfYear(dayOfYear);
        String dtString = dateTime.toString(LasUtils.dateTimeFormatterYYYYMMDD);
        sb.append("File creation date: ").append(dtString).append("\n");
    } else {
        sb.append("File creation Day of Year: ").append(dayOfYear).append("\n");
        sb.append("File creation Year: ").append(year).append("\n");
    }
    sb.append("Header size: ").append(headerSize).append("\n");
    sb.append("Offset to data: ").append(offset).append("\n");
    sb.append("Variable length records: ").append(variableLengthRecordNum).append("\n");
    sb.append("Point data format ID (0-99 for spec): ").append(pointDataFormat).append("\n");
    sb.append("Number of point records: ").append(records).append("\n");
    sb.append("Record length: ").append(recordLength).append("\n");
    sb.append("Scale: [").append(xScale).append(", ").append(yScale).append(", ").append(zScale).append("]\n");
    sb.append("Offset: [").append(xOffset).append(", ").append(yOffset).append(", ").append(zOffset).append("]\n");
    sb.append("X Range: [").append(xMin).append(", ").append(xMax).append("]\n");
    sb.append("Y Range: [").append(yMin).append(", ").append(yMax).append("]\n");
    sb.append("Z Range: [").append(zMin).append(", ").append(zMax).append("]\n");
    sb.append("Has gps time info: ").append(hasGpsTime()).append("\n");
    sb.append("Has color info: ").append(hasRGB()).append("\n");
    sb.append("Gps time type: ").append(gpsTimeType).append("\n");
    return sb.toString();
}
 
Example 5
private List<String[]> getHeaderInfo( ILasHeader header ) {
    List<String[]> headerInfoList = new ArrayList<>();
    headerInfoList.add(new String[]{"File signature", new String(header.getFileSignature())});
    headerInfoList.add(new String[]{"File source ID", "" + header.getFileSourceID()});
    headerInfoList.add(new String[]{"Project ID - data 1", "" + header.getProjectID_GUIDData1()});
    headerInfoList.add(new String[]{"Project ID - data 2", "" + header.getProjectID_GUIDData2()});
    headerInfoList.add(new String[]{"Project ID - data 3", "" + header.getProjectID_GUIDData3()});
    headerInfoList.add(new String[]{"Project ID - data 4", new String(header.getProjectID_GUIDData4())});
    headerInfoList.add(new String[]{"Version", header.getVersion()});
    headerInfoList.add(new String[]{"System identifier", new String(header.getSystemIdentifier())});
    headerInfoList.add(new String[]{"Generating software", header.getGeneratingSoftware()});
    try {
        short fileCreationYear = (short) header.getFileCreationYear();
        short fileCreationDayOfYear = (short) header.getFileCreationDayOfYear();
        String dtString = " - nv - ";
        if (fileCreationYear != 0 && fileCreationDayOfYear != 0) {
            DateTime dateTime = new DateTime();
            dateTime = dateTime.withYear(fileCreationYear).withDayOfYear(fileCreationDayOfYear);
            dtString = dateTime.toString(LasUtils.dateTimeFormatterYYYYMMDD);
        }
        headerInfoList.add(new String[]{"File creation date", dtString});
    } catch (Exception e) {
        e.printStackTrace();
    }
    headerInfoList.add(new String[]{"Header size", "" + header.getHeaderSize()}); //
    headerInfoList.add(new String[]{"Offset to data", "" + header.getOffset()}); //
    headerInfoList.add(new String[]{"Variable length records", "" + header.getNumberOfVariableLengthRecords()}); //
    headerInfoList.add(new String[]{"Point data format ID (0-99 for spec)", "" + header.getPointDataRecordFormat()}); //
    headerInfoList.add(new String[]{"Number of point records", "" + header.getRecordsCount()}); //
    headerInfoList.add(new String[]{"Record length", "" + header.getRecordLength()}); //
    double[] xyzScale = header.getXYZScale();
    headerInfoList.add(new String[]{"Scale", xyzScale[0] + ", " + xyzScale[1] + ", " + xyzScale[2]});
    double[] xyzOffset = header.getXYZOffset();
    headerInfoList.add(new String[]{"Offset", xyzOffset[0] + ", " + xyzOffset[1] + ", " + xyzOffset[2]});
    ReferencedEnvelope3D dataEnvelope3D = header.getDataEnvelope();
    headerInfoList.add(new String[]{"X Range", dataEnvelope3D.getMinX() + ", " + dataEnvelope3D.getMaxX()});
    headerInfoList.add(new String[]{"Y Range", dataEnvelope3D.getMinY() + ", " + dataEnvelope3D.getMaxY()});
    headerInfoList.add(new String[]{"Z Range", dataEnvelope3D.getMinZ() + ", " + dataEnvelope3D.getMaxZ()});
    return headerInfoList;
}
 
Example 6
Source Project: code   File: FileUploadService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @author lastwhisper
 * @desc 生成路径以及文件名 例如://images/2019/04/28/15564277465972939.jpg
 * @email [email protected]
 */
private String getFilePath(String sourceFileName) {
    DateTime dateTime = new DateTime();
    return "images/" + dateTime.toString("yyyy")
            + "/" + dateTime.toString("MM") + "/"
            + dateTime.toString("dd") + "/" + System.currentTimeMillis() +
            RandomUtils.nextInt(100, 9999) + "." +
            StringUtils.substringAfterLast(sourceFileName, ".");
}
 
Example 7
Source Project: shopify-sdk   File: DateTimeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String marshal(final DateTime dateTime) throws Exception {
	if (dateTime == null) {
		return null;
	}
	return dateTime.toString();
}
 
Example 8
/**
 * Stores the state value in each key-value pair in the project's datastore.
 *
 * @param sessionId Request from which to extract session.
 * @param varName   the name of the desired session variable
 * @param varValue  the value of the desired session variable
 */
protected void setSessionVariables(String sessionId, Map<String, String> setMap) {
  if (sessionId.equals("")) {
    return;
  }
  Key key = keyFactory.newKey(sessionId);
  Transaction transaction = datastore.newTransaction();
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  dt.toString(dtf);
  try {
    Entity stateEntity = transaction.get(key);
    Entity.Builder seBuilder;
    if (stateEntity == null) {
      seBuilder = Entity.newBuilder(key);
    } else {
      seBuilder = Entity.newBuilder(stateEntity);
    }
    for (String varName : setMap.keySet()) {
      seBuilder.set(varName, setMap.get(varName));
    }
    transaction.put(seBuilder.set("lastModified", dt.toString(dtf)).build());
    transaction.commit();
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
Example 9
@Override
public String format(DateTime dateTime) {
    return dateTime.toString(DateUtils.COMMON_DATE_FORMAT);
}
 
Example 10
public String generateId() {
   DateTime currentDateTime = new DateTime();
   return currentDateTime.toString("yyyyMMddHHmmss");
}
 
Example 11
Object[][] genCalcdValues() {
    Object[][] retValues = null;
    /*
     * Create an array of Objects that will contain
     * other arrays of Objects. (This is the 'column'
     * array).
     */
    ArrayList fileStrings = lddFile.getFileStrings();
    ArrayList dtObjects = lddFile.getDtObjects();
    int numRows = fileStrings.size();
    retValues = new Object[numRows][];
    int numCols = colNames.length;
    // System.err.println("NumCols : " + numCols);
    /*
     * Prime the array of arrays of Objects, allocating a new
     * secondary array for each of the primary array's
     * elements.
     */
    for (int nextStrNum = 0; nextStrNum < fileStrings.size(); ++ nextStrNum) {
        retValues[nextStrNum] = new Object[numCols]; // get the 'col' array
        //****
        //* This needs to be sync'd with the colNames array.
        //****
        // Current row, 1st column
        int column = 0;
        String fileString = (String)fileStrings.get(nextStrNum);
        retValues[nextStrNum][column++] = fileString;
        // Current row, 2nd column
        DateTime adt = (DateTime)dtObjects.get(nextStrNum);
        String adtStr = adt.toString();
        retValues[nextStrNum][column++] = adtStr;
        // Current row, other columns.
        // Order here must match that specified in the colNames
        // array.
        long lVal = adt.getMillis();
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime( new Date( lVal ) );
        cal.setMinimalDaysInFirstWeek(4);
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.MILLISECOND ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.SECOND ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.MINUTE ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.HOUR_OF_DAY ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.DAY_OF_WEEK ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.DAY_OF_MONTH ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.DAY_OF_YEAR ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.WEEK_OF_YEAR ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.MONTH ) );
        retValues[nextStrNum][column++]  = new Integer( cal.get(
            Calendar.YEAR ) );
        //
    } // the for
    if ( debugf ) dumpObjs( retValues, System.err );
    return retValues;
}
 
Example 12
private String getTime(DateTime time) {
    return time.toString(TIME_FORMAT);
}
 
Example 13
Object[][] genCalcdValues() {
    Object[][] retValues = null;
    /*
     * Create an array of Objects that will contain
     * other arrays of Objects. (This is the 'column'
     * array).
     */
    ArrayList fileStrings = lddFile.getFileStrings();
    ArrayList dtObjects = lddFile.getDtObjects();
    int numRows = fileStrings.size();
    retValues = new Object[numRows][];
    int numCols = colNames.length;
    // System.err.println("NumCols : " + numCols);
    String fs = "yyyy-MM-dd'T'HH:mm:ss";
    DateFormat df = new SimpleDateFormat( fs );
    /*
     * Prime the array of arrays of Objects, allocating a new
     * secondary array for each of the primary array's
     * elements.
     */
    for (int nextStrNum = 0; nextStrNum < fileStrings.size(); ++ nextStrNum) {
        retValues[nextStrNum] = new Object[numCols]; // get the 'col' array
        //****
        //* This needs to be sync'd with the colNames array.
        //****
        // Current row, 1st column
        int column = 0;
        String fileString = (String)fileStrings.get(nextStrNum);
        retValues[nextStrNum][column++] = fileString;
        // Current row, 2nd column
        DateTime adt = (DateTime)dtObjects.get(nextStrNum);
        String adtStr = adt.toString();
        retValues[nextStrNum][column++] = adtStr;
        // Current row, other columns.
        // Order here must match that specified in the colNames
        // array.
        long lVal = adt.getMillis();
        Long millis = new Long( lVal );
        retValues[nextStrNum][column++]  = millis;
        String hexVal = Long.toHexString( lVal );
        String octalVal = Long.toOctalString( lVal );
        retValues[nextStrNum][column++]  = "0"+ LPad(octalVal,22);
        retValues[nextStrNum][column++]  = "0x" + LPad(hexVal,16);
        //
        Date javaDate = null;
        try
        {
            javaDate = df.parse( fileString );
        }
        catch(ParseException e)
        {
            System.err.println("Parse failed for : " + fileString);
            // pe.printStackTrace();
        }
        //
        lVal = javaDate.getTime();
        millis = new Long( lVal );
        hexVal = Long.toHexString( lVal );
        octalVal = Long.toOctalString( lVal );
        retValues[nextStrNum][column++]  = millis;
        retValues[nextStrNum][column++]  = "0"+ LPad(octalVal,22);
        retValues[nextStrNum][column++]  = "0x" + LPad(hexVal,16);
        //
    } // the for
    if ( debugf ) dumpObjs( retValues, System.err );
    return retValues;
}
 
Example 14
Source Project: liteflow   File: ThursdayCalculator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String format(DateTime dateTime) {
    return dateTime.toString(DateUtils.COMMON_DATE_FORMAT);
}
 
Example 15
public Stream<String> queriesForInterval(@NonNull DateTime begin, @NonNull DateTime end) {
    final String querySuffix = " WHERE time > '" + begin.toString() + "' and time <= '" + end.toString() + "' GROUP BY * ORDER BY time ASC";
    return selectStmts.stream().map(select -> select + querySuffix);
}
 
Example 16
Source Project: streamx   File: TimeUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String encodeTimestamp(long partitionDurationMs, String pathFormat, String timeZoneString, long timestamp) {
  DateTimeZone timeZone = DateTimeZone.forID(timeZoneString);
  DateTimeFormatter formatter = DateTimeFormat.forPattern(pathFormat).withZone(timeZone);
  DateTime partition = new DateTime(getPartition(partitionDurationMs, timestamp, timeZone));
  return partition.toString(formatter);
}
 
Example 17
public InputReference() throws TechnicalConnectorException {
   DateTime currentDateTime = new DateTime();
   this.inputReference = currentDateTime.toString("yyyyMMddHHmmss");
}
 
Example 18
Source Project: open-rmbt   File: ServerResource.java    License: Apache License 2.0 4 votes vote down vote up
public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context)
{
    return new JsonPrimitive(src.toString());
}
 
Example 19
Source Project: liteflow   File: DateUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 格式化为日期2019-01-31
 *
 * @param date
 * @return
 */
public static String formatToDateStr(Date date) {
    DateTime dateTime = new DateTime(date);
    return dateTime.toString(COMMON_DATE_FORMAT);
}
 
Example 20
Source Project: SkyEye   File: MonitorTask.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 根据时间戳获取开始时间
 * @param timestamp
 * @param window
 * @return
 */
private String getBegin(long timestamp, int window) {
    DateTime end = new DateTime(timestamp).minusSeconds(this.delay);
    DateTime begin = end.minusMinutes(window);
    return begin.toString(DateUtil.YYYYMMDDHHMMSS);
}