Example usage for org.joda.time DateTime now

List of usage examples for org.joda.time DateTime now

Introduction

In this page you can find the example usage for org.joda.time DateTime now.

Prototype

public static DateTime now(Chronology chronology) 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using the specified chronology.

Usage

From source file:com.eldar.services.ResourceService.java

License:Open Source License

private String getFileName(String name, int version) {
    return name + "_" + version + "_" + DateTime.now(DateTimeZone.UTC).toString("yyyy-MM-dd-HH-mm-ss");
}

From source file:com.evinceframework.membership.authentication.UserUpdater.java

License:Apache License

protected DateTime utcNow() {
    return DateTime.now(DateTimeZone.UTC);
}

From source file:com.example.getstarted.util.CloudStorageHelper.java

License:Apache License

/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 *//*from   w ww  .j a  va2s .  co m*/
public String uploadFile(FileItemStream fileStream, final String bucketName)
        throws IOException, ServletException {
    checkFileExtension(fileStream.getName());

    DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
    DateTime dt = DateTime.now(DateTimeZone.UTC);
    String dtString = dt.toString(dtf);
    final String fileName = fileStream.getName() + dtString;

    // the inputstream is closed by default, so we don't need to close it here
    BlobInfo blobInfo = storage.create(BlobInfo.newBuilder(bucketName, fileName)
            // Modify access list to allow all users with link to read file
            .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER)))).build(),
            fileStream.openStream());
    logger.log(Level.INFO, "Uploaded file {0} as {1}", new Object[] { fileStream.getName(), fileName });
    // return the public download link
    return blobInfo.getMediaLink();
}

From source file:com.example.getstarted.util.DatastoreSessionFilter.java

License:Apache License

@Override
public void init(FilterConfig config) throws ServletException {
    // initialize local copy of datastore session variables

    datastore = DatastoreServiceFactory.getDatastoreService();
    // Delete all sessions unmodified for over two days
    DateTime dt = DateTime.now(DateTimeZone.UTC);
    Query query = new Query(SESSION_KIND).setFilter(new FilterPredicate("lastModified",
            FilterOperator.LESS_THAN_OR_EQUAL, dt.minusDays(2).toString(DTF)));
    Iterator<Entity> results = datastore.prepare(query).asIterator();
    while (results.hasNext()) {
        Entity stateEntity = results.next();
        datastore.delete(stateEntity.getKey());
    }/*from w w w . j  a  v a  2 s.  co m*/
}

From source file:com.example.getstarted.util.DatastoreSessionFilter.java

License:Apache License

/**
 * 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
 *//*from   w w w .  ja va 2  s.  c  o m*/
protected void setSessionVariables(String sessionId, Map<String, String> setMap) {
    if (sessionId.equals("")) {
        return;
    }
    Key key = KeyFactory.createKey(SESSION_KIND, sessionId);
    Transaction transaction = datastore.beginTransaction();
    DateTime dt = DateTime.now(DateTimeZone.UTC);
    dt.toString(DTF);
    try {
        Entity stateEntity;
        try {
            stateEntity = datastore.get(transaction, key);
        } catch (EntityNotFoundException e) {
            stateEntity = new Entity(key);
        }
        for (String varName : setMap.keySet()) {
            stateEntity.setProperty(varName, setMap.get(varName));
        }
        stateEntity.setProperty("lastModified", dt.toString(DTF));
        datastore.put(transaction, stateEntity);
        transaction.commit();
    } finally {
        if (transaction.isActive()) {
            transaction.rollback();
        }
    }
}

From source file:com.example.managedvms.gettingstartedjava.util.CloudStorageHelper.java

License:Open Source License

/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 *///from  w  ww .  jav a 2 s . co m
public String uploadFile(Part filePart, final String bucketName) throws IOException {
    DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
    DateTime dt = DateTime.now(DateTimeZone.UTC);
    String dtString = dt.toString(dtf);
    final String fileName = filePart.getSubmittedFileName() + dtString;

    // the inputstream is closed by default, so we don't need to close it here
    BlobInfo blobInfo = storage.create(BlobInfo.builder(bucketName, fileName)
            // Modify access list to allow all users with link to read file
            .acl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER)))).build(),
            filePart.getInputStream());
    logger.log(Level.INFO, "Uploaded file {0} as {1}",
            new Object[] { filePart.getSubmittedFileName(), fileName });
    // return the public download link
    return blobInfo.mediaLink();
}

From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java

License:Apache License

/**
 * Creates a GPS time based upon the current time.
 */
public static GpsTime now() {
    return fromUtc(DateTime.now(DateTimeZone.UTC));
}

From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java

License:Apache License

/**
 * Creates a GPS time using YUMA GPS week number (0..1023), and the time of week.
 * @param yumaWeek (0..1023)// w ww.j ava2s. c  o m
 * @param towSec GPS time of week in second
 * @return actual time in GpsTime.
 */
public static GpsTime fromYumaWeekTow(int yumaWeek, int towSec) {
    Preconditions.checkArgument(yumaWeek >= 0);
    Preconditions.checkArgument(yumaWeek < 1024);

    // Estimate the multiplier of current week.
    DateTime currentTime = DateTime.now(UTC_ZONE);
    GpsTime refTime = new GpsTime(currentTime);
    Pair<Integer, Integer> refWeekSec = refTime.getGpsWeekSecond();
    int weekMultiplier = refWeekSec.first / 1024;

    int gpsWeek = weekMultiplier * 1024 + yumaWeek;
    return fromWeekTow(gpsWeek, towSec);
}

From source file:com.google.location.lbs.gnss.gps.pseudorange.GpsTime.java

License:Apache License

/**
 * @return Day of year in GPS time (GMT time)
 *///from w w w  . ja  v  a 2  s  .co  m
public static int getCurrentDayOfYear() {
    DateTime current = DateTime.now(DateTimeZone.UTC);
    // Since current is derived from UTC time, we need to add leap second here.
    long gpsTimeMillis = current.getMillis() + getLeapSecond(current);
    DateTime gpsCurrent = new DateTime(gpsTimeMillis, UTC_ZONE);
    return gpsCurrent.getDayOfYear();
}

From source file:com.google.samples.apps.abelana.AbelanaThings.java

License:Open Source License

public static String getImage(String name) {
    final String Bucket = "abelana";
    DateTime soon = DateTime.now(DateTimeZone.UTC).plusMinutes(20);
    long expires = soon.getMillis() / 1000;
    String stringToSign = "GET\n\n\n" + expires + "\n" + "/" + Bucket + "/" + name + ".webp";

    String uri = "https://storage.googleapis.com/abelana/" + name + ".webp" + "?GoogleAccessId="
            + credential.getServiceAccountId() + "&Expires=" + expires + "&Signature="
            + Uri.encode(signData(stringToSign));

    return uri;//www. j av a 2  s .  c o  m

}