Beispiel #1
0
  public static void main(String[] args) {
    LocalDateTime localDateTime = LocalDateTime.of(2016, 3, 27, 1, 20);
    localDateTime = localDateTime.plusHours(1);
    System.out.println(localDateTime);

    ZoneId zoneId = ZoneId.of("Europe/Warsaw");
    ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zoneId);
    System.out.println(zonedDateTime);
  }
Beispiel #2
0
 public static void main(String[] args) {
   LocalDate date = LocalDate.of(2015, Month.JULY, 6);
   LocalTime time = LocalTime.of(15, 25);
   LocalDateTime dateTime = LocalDateTime.of(date, time);
   printSectionName("LocalDateTime");
   System.out.println(dateTime);
   System.out.println(dateTime.minusDays(1));
   System.out.println(dateTime.minusHours(5));
   System.out.println(dateTime.minusSeconds(7));
   printDelimiterString();
 }
Beispiel #3
0
  @Test
  public void shouldPlayWithDates() {
    LocalDate d1 = LocalDate.now();
    LocalDate d2 = LocalDate.of(2014, 2, 15).plusDays(10);
    print(d1);
    print(d2);

    LocalDateTime d3 = d2.atTime(13, 23, 34, 45);
    assertThat(d3.toString(), is("2014-02-25T13:23:34.000000045"));
    LocalDateTime d4 = d3.plus(Period.of(1, 2, 3));
    assertThat(d4.toString(), is("2015-04-28T13:23:34.000000045"));
  }
Beispiel #4
0
  static void f3() {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss");
    LocalDateTime dateTime = LocalDateTime.now();
    String string = formatter.format(dateTime);
    System.out.println(string);

    DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss");
    LocalDateTime dateTime1 = LocalDateTime.parse("20160124-15:03:59", formatter1);
    System.out.println(dateTime1);

    // LocalDateTime dt1 = LocalDateTime.of(2016, Month.JANUARY, 10, 20, 30);
    // LocalDateTime dt2 = LocalDateTime.of(date, time);
    // LocalDateTime dt3 = date.atTime(20, 30);
    // LocalDateTime dt4 = date.atTime(time);
  }
Beispiel #5
0
  @Test
  public void testBasic() {
    System.out.println(Year.now());
    System.out.println(Year.of(2015));
    System.out.println(Year.isLeap(2016));

    Locale locale = Locale.getDefault();
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.SHORT, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.NARROW, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL_STANDALONE, locale));
    System.out.println(Month.of(8).ordinal());
    System.out.println(Month.AUGUST.minus(2));

    System.out.println(YearMonth.now());
    System.out.println(MonthDay.now());

    System.out.println(DayOfWeek.FRIDAY.plus(2));
    System.out.println(DayOfWeek.of(1));
    System.out.println(
        DayOfWeek.from(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault())));

    System.out.println(Period.between(Year.now().atDay(1), LocalDate.now()));
    System.out.println(ChronoUnit.DAYS.between(Year.now().atDay(1), LocalDate.now()));
  }
 /**
  * The main method.
  *
  * @param args the arguments
  */
 public static void main(String[] args) {
   try {
     FEMultiplayer game = new FEMultiplayer();
     //			SoundTrack.enabled = false;
     game.init(480, 320, "Fire Emblem Multiplayer");
     /* Testing code */
     //			game.testFightStage();
     //			game.testOverworldStage();
     //			game.testDraftStage();
     game.loop();
   } catch (Exception e) {
     System.err.println("Exception occurred, writing to logs...");
     e.printStackTrace();
     try {
       File errLog =
           new File(
               "error_log_client"
                   + LocalDateTime.now().toString().replace("T", "@").replace(":", "-")
                   + ".log");
       PrintWriter pw = new PrintWriter(errLog);
       e.printStackTrace(pw);
       pw.close();
     } catch (IOException e2) {
       e2.printStackTrace();
     }
     System.exit(0);
   }
 }
public class ApacheCombinedFormatLoggerTest {
  LogRecordingHandler logRecords = new LogRecordingHandler();
  Instant currentTime = LocalDateTime.of(2012, 6, 27, 12, 4, 0).toInstant(ZoneOffset.of("-05:00"));
  ApacheCombinedFormatLogger apacheCommonLogger =
      new ApacheCombinedFormatLogger(
          anonymousLogger(logRecords), Clock.fixed(currentTime, ZoneId.of("GMT+01:00")), Locale.US);

  Request request = new Request().protocol("HTTP/1.1").remoteIp("192.168.0.1");
  Response response = new Response();

  @Test
  public void logsRequestsServedInApacheCombinedLogFormat() throws Exception {
    request
        .method(GET)
        .uri("/products?keyword=dogs")
        .addHeader(HeaderNames.REFERER, "http://lama/wool")
        .addHeader(HeaderNames.USER_AGENT, "Mozilla/5.0 (compatible; MSIE 9.0; AOL 9.7)");

    apacheCommonLogger.handle(request, response);
    response.status(OK).body("a response with a size of 28").done();

    response.await();
    logRecords.assertEntries(
        contains(
            "192.168.0.1 - - [27/Jun/2012:18:04:00 +0100] \"GET /products?keyword=dogs HTTP/1.1\" 200 28 \"http://lama/wool\" \"Mozilla/5.0 (compatible; MSIE 9.0; AOL 9.7)\""));
  }

  @Test
  public void logsEmptyStringWhenNoUserAgentInRequest() throws Exception {
    request
        .method(GET)
        .uri("/products?keyword=dogs")
        .addHeader(HeaderNames.REFERER, "http://lama/wool");

    apacheCommonLogger.handle(request, response);
    response.status(OK).body("a response with a size of 28").done();

    response.await();
    logRecords.assertEntries(
        contains(
            "192.168.0.1 - - [27/Jun/2012:18:04:00 +0100] \"GET /products?keyword=dogs HTTP/1.1\" 200 28 \"http://lama/wool\" \"\""));
  }

  @Test
  public void logsEmptyStringWhenNoRefererInRequest() throws Exception {
    request
        .method(GET)
        .uri("/products?keyword=dogs")
        .addHeader(HeaderNames.USER_AGENT, "Mozilla/5.0 (compatible; MSIE 9.0; AOL 9.7)");

    apacheCommonLogger.handle(request, response);
    response.status(OK).body("a response with a size of 28").done();

    response.await();
    logRecords.assertEntries(
        contains(
            "192.168.0.1 - - [27/Jun/2012:18:04:00 +0100] \"GET /products?keyword=dogs HTTP/1.1\" 200 28 \"\" \"Mozilla/5.0 (compatible; MSIE 9.0; AOL 9.7)\""));
  }
}
Beispiel #8
0
  public Tweet(String user, String text) {
    if (!user.contains(" ")) ; // usernames cannot have spaces
    username = user;
    if (tweetText.isEmpty()
        && text.length() <= 140) { // tweet length cannot be more than 140 characters
      tweetText = text;
    }
    timePosted = LocalDateTime.now();

    parseTweet();
  }
Beispiel #9
0
  @Test
  public void testLocalDateTime() {
    System.out.println(LocalDateTime.now());
    System.out.println(LocalDateTime.of(1994, Month.MAY, 15, 11, 30));
    System.out.println(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()));
    System.out.println(LocalDateTime.ofEpochSecond(1450749600, 0, ZoneOffset.ofHours(8)));

    System.out.printf("6 months from now: %s%n", LocalDateTime.now().plusMonths(6));
    System.out.printf("6 days ago: %s%n", LocalDateTime.now().minusDays(6));

    System.out.println(DateTimeFormatter.ISO_DATE_TIME.format(LocalDateTime.now()));
    System.out.println(DateTimeFormatter.ofPattern("MM-dd HH:mm").format(LocalDateTime.now()));
  }
 public static void main(String[] args) {
   int startTime, endTime;
   final int TIMES = 200_000;
   final int FACTOR = 1_000_000;
   int x;
   StringBuilder string1 = new StringBuilder("");
   StringBuilder string2 = new StringBuilder(TIMES * 4);
   LocalDateTime now;
   now = LocalDateTime.now();
   startTime = now.getNano();
   for (x = 0; x < TIMES; ++x) string1.append("Java");
   now = LocalDateTime.now();
   endTime = now.getNano();
   System.out.println(
       "Time with empty StringBuilder: " + ((endTime - startTime) / FACTOR + " milliseconds"));
   now = LocalDateTime.now();
   startTime = now.getNano();
   for (x = 0; x < TIMES; ++x) string2.append("Java");
   now = LocalDateTime.now();
   endTime = now.getNano();
   System.out.println(
       "Time with empty StringBuilder: " + ((endTime - startTime) / FACTOR + " milliseconds"));
 }
Beispiel #11
0
  private static void newAPI() {
    LocalDate soloFecha = LocalDate.now();
    LocalTime soloHora = LocalTime.now();
    LocalDateTime todo = LocalDateTime.now();

    ZonedDateTime zonedDateTime = ZonedDateTime.now();

    System.out.println("La fecha " + soloFecha);
    System.out.println("La hora " + soloHora);
    System.out.println("La fecha hora " + todo);
    System.out.println("La fecha hora y zona " + zonedDateTime);

    LocalDate myFecha = LocalDate.of(2015, Month.JULY, 2);
    LocalTime myHora = LocalTime.of(9, 21);

    System.out.println("Ayer fue: " + myFecha);
    System.out.println("La hora fue: " + myHora);
  }
 @Override
 public Date convert(LocalDateTime source) {
   return source == null ? null : Date.from(source.atZone(ZoneId.systemDefault()).toInstant());
 }
Beispiel #13
0
 private static LocalDateTime parseDateTime(String value) {
   return LocalDateTime.parse(value);
 }
 public void setTime(int hour, int minute, int second) {
   LocalDate currentDate = LocalDate.from(dateAndTime);
   LocalTime timeToSet = LocalTime.of(hour, minute, second);
   dateAndTime = LocalDateTime.of(currentDate, timeToSet);
 }
 public void setDate(int day, int month, int year) {
   LocalDate dateToSet = LocalDate.of(day, month, year);
   LocalTime currentTime = LocalTime.from(dateAndTime);
   dateAndTime = LocalDateTime.of(dateToSet, currentTime);
 }
 public void setDateAndTime(int day, int month, int year, int hour, int minute, int second) {
   LocalDate dateToSet = LocalDate.of(day, month, year);
   LocalTime timeToSet = LocalTime.of(hour, minute, second);
   dateAndTime = LocalDateTime.of(dateToSet, timeToSet);
 }
Beispiel #17
0
 public String getTimePosted() { // returns time posted as a string
   return timePosted.toString();
 }
Beispiel #18
0
 public String
     getTimeSincePosted() { // returns difference in minutes between current time & time posted
                            // (could be made much more specific)
   return LocalDateTime.now().minusMinutes(timePosted.getMinute()).toString();
 }
 public SimpleAnotherTimeClient() {
   dateAndTime = LocalDateTime.now();
 }
 @Override
 public LocalDateTime convert(Date source) {
   return source == null
       ? null
       : LocalDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());
 }
 public String toString() {
   return dateAndTime.toString();
 }
 // -----------------------------------------------------------------------
 public void testAddToLocalDate() {
   Minutes test = Minutes.minutes(26);
   LocalDateTime date = new LocalDateTime(2006, 6, 1, 0, 0, 0, 0);
   LocalDateTime expected = new LocalDateTime(2006, 6, 1, 0, 26, 0, 0);
   assertEquals(expected, date.plus(test));
 }
 /** TimePointを生成します。 */
 public static TimePoint now(Clock clock) {
   LocalDateTime now = LocalDateTime.now(clock);
   return of(now.toLocalDate(), now);
 }
Beispiel #24
0
 public Tweet() {
   timePosted = LocalDateTime.now();
 }
Beispiel #25
0
 public void test_getValue_Calendrical_dateTime() {
   Calendrical cal = LocalDateTime.of(2007, 6, 20, 12, 30);
   assertEquals(rule().getValue(cal), rule().field(2007));
 }