Example usage for java.time ZonedDateTime toString

List of usage examples for java.time ZonedDateTime toString

Introduction

In this page you can find the example usage for java.time ZonedDateTime toString.

Prototype

@Override 
public String toString() 

Source Link

Document

Outputs this date-time as a String , such as 2007-12-03T10:15:30+01:00[Europe/Paris] .

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();

    System.out.println(dateTime.toString());
}

From source file:DataTools.ConvertObjectToJson.java

/**
 * add the datetime object in correct format
 * date objects come out all messed up/*from ww w  .j  a  v a2 s.co m*/
 * change them to a string of the date
 */
public static String cleanupDate(ZonedDateTime date) {
    return date.toString().split("T")[0];
}

From source file:com.match_tracker.twitter.TwitterSearch.java

protected void waitUntilStartIsInThePast(ZonedDateTime startTime) {
    long searchDelay = calculateSearchDelay(startTime);

    if (searchDelay > 0) {
        log.log(Level.INFO, "Twitter search start in the future, sleeping {1}ms until {0}",
                new Object[] { startTime.toString(), String.valueOf(searchDelay) });
        sleep(searchDelay);//  w  w  w  .  j  a  v a2s  . c om
    }
}

From source file:DataStorageTests.java

@Test
public void dateTest() {
    storage = new Storage("{'lower':{}}");
    ZonedDateTime now = ZonedDateTime.now();
    Date dNow = new Date();
    String dNowString = dNow.toString();
    String dateNow = now.toString().split("T")[0];

    storage.put("date", now);
    storage.put(new String[] { "lower", "date" }, now);
    storage.put(new String[] { "lower", "otherDate" }, dNow);

    Assert.assertEquals(dateNow, storage.get("date"));
    Assert.assertEquals(dateNow, storage.get(new String[] { "lower", "date" }));
    Assert.assertEquals(dNowString, storage.getString(new String[] { "lower", "otherDate" }));

    // for testing the parsing of an object with date time objects
    class Inner {
        public ZonedDateTime getDate() {
            return now;
        }//  w w w  .ja  va 2s . c  om

        public Date getOtherDate() {
            return dNow;
        }
    }

    class Top {
        public ZonedDateTime getDate() {
            return now;
        }

        public Inner getInner() {
            return new Inner();
        }
    }

    Top test = new Top();
    storage = new Storage(test);

    Assert.assertEquals(dateNow, storage.get("date"));
    Assert.assertEquals(dateNow, storage.get(new String[] { "inner", "date" }));
    Assert.assertEquals(dNowString, storage.get(new String[] { "inner", "otherDate" }));

    storage = new Storage();
    storage.addModel(test);

    Assert.assertEquals(dateNow, storage.get("date"));
    Assert.assertEquals(dateNow, storage.get(new String[] { "inner", "date" }));
    Assert.assertEquals(dNowString, storage.get(new String[] { "inner", "otherDate" }));

    storage.put("test", test);

    Assert.assertEquals(dateNow, storage.get(new String[] { "test", "date" }));
    Assert.assertEquals(dateNow, storage.get(new String[] { "test", "inner", "date" }));
    Assert.assertEquals(dNowString, storage.get(new String[] { "test", "inner", "otherDate" }));

    //array list of objects that have DateTime
    ArrayList<Top> list = new ArrayList<>();
    list.add(new Top());
    list.add(new Top());

    storage = new Storage(list);

    Assert.assertEquals(dateNow, storage.get(new String[] { "0", "date" }));
    Assert.assertEquals(dateNow, storage.get(new String[] { "1", "inner", "date" }));
    Assert.assertEquals(dNowString, storage.get(new String[] { "0", "inner", "otherDate" }));
    Assert.assertEquals("{\"date\":\"" + dateNow + "\",\"otherDate\":\"" + dNowString + "\"}",
            storage.getAsDataStorage(new String[] { "1", "inner" }).toString());
}

From source file:org.qcert.camp.translator.SemRule2CAMP.java

/**
 * Incomplete but evolving translation for object allocations involving temporal constructs
 * @param ast the object allocation (SemNewObject)
 * @return the translation//w  w w .j a v  a 2 s.  c  o m
 */
private CampPattern translateTemporalAllocation(SemNewObject ast) {
    List<SemValue> args = ast.getArguments();
    if (DATE_TYPE.equals(ast.getType().getDisplayName())) {
        Iterator<SemValue> argIter = args.iterator();
        ZonedDateTime translation = ZonedDateTime.ofInstant(Instant.EPOCH, ZoneId.systemDefault())
                .withYear(intFrom(argIter.next())).withMonth(intFrom(argIter.next()))
                .withDayOfMonth(intFrom(argIter.next()));
        if (argIter.hasNext())
            translation = translation.withHour(intFrom(argIter.next()));
        if (argIter.hasNext())
            translation = translation.withMinute(intFrom(argIter.next()));
        if (argIter.hasNext())
            translation = translation.withSecond(intFrom(argIter.next()));
        ConstPattern constant = new ConstPattern(translation.toString());
        return new UnaryPattern(UnaryOperator.ATimeFromString, constant);
    }
    if (TIME_TYPE.equals(ast.getType().getDisplayName()) && args.size() == 1) {
        long epochMilli = longFrom(args.get(0));
        LocalTime translation = ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC)
                .toLocalTime();
        // TODO this should really be a unique CAMP type corresponding to the TTRL type for LocalTimeComponentValue
        return new ConstPattern(translation.toString());
    }
    return notImplemented("Translation of temporal allocation: " + ast);
}