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.cyngn.vertx.opentsdb.service.MetricsParser.java

License:Apache License

/**
 * Given the raw metric data create an OpenTsDb formatted string.
 *
 * @param name the metric name//from   www.  ja  v a2 s.c  o  m
 * @param value the metric value
 * @param tags the tags string for this data point
 * @return an OpenTsDb metric string
 */
public String getMetricString(String name, String value, String tags) {
    long timestamp = DateTime.now(DateTimeZone.UTC).toDate().getTime();
    return (hasPrefix) ? String.format("put %s.%s %d %s %s\n", prefix, name, timestamp, value, tags)
            : String.format("put %s %d %s %s\n", name, timestamp, value, tags);
}

From source file:com.digi.android.wva.DashboardActivity.java

License:Mozilla Public License

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        navigateBackToDevices();/*from   w w w  .  ja v a 2  s . c o m*/
        return true;
    case R.id.sync_time:
        Log.d(TAG, "Executing time sync.");
        WvaApplication app = (WvaApplication) getApplication();
        if (app.getDevice() != null)
            app.getDevice().setTime(DateTime.now(DateTimeZone.UTC), new WvaCallback<DateTime>() {
                @Override
                public void onResponse(Throwable error, DateTime response) {
                    Log.d(TAG, "Time sync error: " + error);
                    String message;
                    if (error == null)
                        message = "Time sync successful.";
                    else
                        message = "Time sync: " + error;
                    Toast.makeText(DashboardActivity.this, message, Toast.LENGTH_SHORT).show();
                }
            });
        else
            Log.d(TAG, "Can't execute time sync: no Device in WvaApplication");
        return true;
    // startActivityForResult should make it so that backing out (i.e. finish()ing)
    // from the launched activities returns us here to DashboardActivity
    case R.id.action_settings:
        startActivityForResult(new Intent(this, SettingsActivity.class), 0);
        return true;
    case R.id.launch_chart:
        startActivityForResult(new Intent(this, ChartActivity.class), 0);
        return true;
    case R.id.fault_codes:
        startActivity(new Intent(this, FaultCodeActivity.class));
        return true;
    }
    return false;
}

From source file:com.digi.wva.test_auxiliary.SimulatedEventChannel.java

License:Mozilla Public License

/**
 * Construct a template event channel JSON object, containing a timestamp and
 * with the top-level key corresponding to the event type ("data" or "alarm").
 * @param type the event type to use//from www  .  j  a v a 2s.co m
 * @return a template JSON object
 * @throws JSONException if there is an error in building this JSON
 */
private JSONObject buildStub(EventFactory.Type type) throws JSONException {
    JSONObject stub = new JSONObject();
    String timestamp = formatter.print(DateTime.now(DateTimeZone.UTC));

    // Add inner object
    stub.put(type == EventFactory.Type.SUBSCRIPTION ? "data" : "alarm",
            new JSONObject().put("timestamp", timestamp));

    return stub;
}

From source file:com.dtstack.jlogstash.utils.Public.java

License:Apache License

public static String getTimeStamp(DateTimeZone timeZone) {
    return timeZone != null ? DateTime.now(timeZone).toString() : DateTime.now().toString();
}

From source file:com.edlogics.ElrcApplication.java

License:Open Source License

/**
 * If the application is currently in maintenance as specified by the maintenance date time being set.
 *
 * @return Is the current date time > maintenance date time?
 */// w  ww .j  ava 2s  . co  m
@Bean
@Scope(WebApplicationContext.SCOPE_REQUEST)
public boolean inMaintenance() {
    DateTime currentDateTime = DateTime.now(DateTimeZone.forID(elrcTimezone));
    return (currentDateTime.getMillis() - maintenanceDateTime().getMillis()) > 0;
}

From source file:com.eldar.daos.mybatis.MyBatisContainerDao.java

License:Open Source License

@Override
public void save(Container container) {
    SqlSession session = sqlSessionFactory.openSession();
    try {/*from   ww  w  .j a v a 2 s . c  o  m*/
        DateTime current = DateTime.now(DateTimeZone.UTC);
        container.setModifiedDate(current);
        for (CssClass cssClass : container.getCssClassList()) {
            cssClassDao.save(cssClass);
        }
        if (container.getId() > 0) {
            containerMapper.update(container);
        } else {
            container.setCreatedDate(current);
            containerMapper.insert(container);
        }
        for (CssClass cssClass : container.getCssClassList()) {
            cssClassDao.saveContainerRel(cssClass, container);
        }

    } catch (Exception ex) {
        logger.error("Error saving container", ex);
    } finally {
        session.commit();
        session.close();
    }
}

From source file:com.eldar.daos.mybatis.MyBatisCssClassDao.java

License:Open Source License

public void save(CssClass cssClass) {
    SqlSession session = sqlSessionFactory.openSession();
    try {/*from   w  w w .jav  a  2  s.c  om*/
        DateTime current = DateTime.now(DateTimeZone.UTC);
        cssClass.setModifiedDate(current);
        if (cssClass.getId() > 0) {
            cssClassMapper.update(cssClass);
        } else {
            cssClass.setCreatedDate(current);
            cssClassMapper.insert(cssClass);
        }
    } catch (Exception ex) {
        logger.error("Error saving css class", ex);
    } finally {
        session.commit();
        session.close();
    }
}

From source file:com.eldar.daos.mybatis.MyBatisResourceDao.java

License:Open Source License

@Override
public void save(Resource resource) {
    SqlSession session = sqlSessionFactory.openSession();
    try {/*from  w  w w.  j a  va 2  s  . com*/
        DateTime dateTime = DateTime.now(DateTimeZone.UTC);
        resource.setModifiedDate(dateTime);
        if (resource.getId() == 0) {
            resource.setCreatedDate(dateTime);
            resourceMapper.insert(resource);
        } else {
            resourceMapper.update(resource);
        }
    } finally {
        session.commit();
        session.close();
    }
}

From source file:com.eldar.daos.mybatis.MyBatisResourceTypeDao.java

License:Open Source License

@Override
public void save(ResourceType resourceType) {
    SqlSession session = sqlSessionFactory.openSession();
    try {// ww  w  .j  av a 2  s.  com
        DateTime dateTime = DateTime.now(DateTimeZone.UTC);
        resourceType.setModifiedDate(dateTime);
        if (resourceType.getId() == 0) {
            resourceType.setCreatedDate(dateTime);
            resourceTypeMapper.insert(resourceType);
        } else {
            resourceTypeMapper.update(resourceType);
        }
    } finally {
        session.commit();
        session.close();
    }
}

From source file:com.eldar.models.Base.java

License:Open Source License

public Base() {
    setCreatedDate(DateTime.now(DateTimeZone.UTC));
    setModifiedDate(getCreatedDate());
}