Example usage for java.time LocalDateTime now

List of usage examples for java.time LocalDateTime now

Introduction

In this page you can find the example usage for java.time LocalDateTime now.

Prototype

public static LocalDateTime now() 

Source Link

Document

Obtains the current date-time from the system clock in the default time-zone.

Usage

From source file:org.darkware.wpman.util.TimeWindow.java

/**
 * Calculates the next time when a given hour and minute occur, based from the current time.
 *
 * @param hour The hour to search for.//  w w  w .ja  v a  2 s .  c  om
 * @param minute The minute to search for.
 * @return A {@code DateTime} corresponding to the hour and minute declared which is explicitly after
 * the current time.
 */
public static LocalDateTime nextTime(final int hour, final int minute) {
    return TimeWindow.nextTime(LocalDateTime.now(), hour, minute);
}

From source file:com.github.philippn.springremotingautoconfigure.sample.server.TimeServiceImpl.java

@Override
public LocalDateTime serverTime() {
    return LocalDateTime.now();
}

From source file:mServer.tool.MserverDatumZeit.java

public static long getSecondsUntilNextDay() {
    // now//from   w  ww. ja  v  a 2 s .c  om
    LocalDateTime now = LocalDateTime.now();
    // tomorrow 0:00
    LocalDateTime future = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).plusDays(1L);
    Duration duration = Duration.between(now, future);
    return duration.getSeconds();
}

From source file:net.dv8tion.discord.util.GoogleSearch.java

public static List<SearchResult> performSearch(String engineId, String terms, int requiredResultsCount) {
    try {//  w w  w.java  2  s.  c  o  m
        if (GOOGLE_API_KEY == null)
            throw new IllegalStateException(
                    "Google API Key is null, Cannot preform google search without a key! Set one in the settings!");
        if (engineId == null || engineId.isEmpty())
            throw new IllegalArgumentException("Google Custom Search Engine id cannot be null or empty!");

        LocalDateTime currentTime = LocalDateTime.now();
        if (currentTime.isAfter(dayStartTime.plusDays(1))) {
            dayStartTime = currentTime;
            currentGoogleUsage = 1;
        } else if (currentGoogleUsage >= 80) {
            throw new IllegalStateException("Google usage has reached the premature security cap of 80");
        }

        terms = terms.replace(" ", "%20");
        String searchUrl = String.format(GOOGLE_URL, engineId, GOOGLE_API_KEY, requiredResultsCount, terms);

        URL searchURL = new URL(searchUrl);
        URLConnection conn = searchURL.openConnection();
        currentGoogleUsage++;
        conn.setRequestProperty("User-Agent",
                "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 " + randomName(10));
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuilder json = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
            json.append(line).append("\n");
        }
        in.close();

        JSONArray jsonResults = new JSONObject(json.toString()).getJSONArray("items");
        List<SearchResult> results = new LinkedList<>();
        for (int i = 0; i < jsonResults.length(); i++) {
            results.add(SearchResult.fromGoogle(jsonResults.getJSONObject(i)));
        }
        return results;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.example.data.Message.java

@PrePersist
public void setCreated() {
    this.created = LocalDateTime.now();
}

From source file:sbjee.Sender.java

@Scheduled(fixedDelay = 1000L)
public void send() {
    this.messaging.convertAndSend("testQueue", "Hello it's " + LocalDateTime.now());
}

From source file:fi.helsinki.opintoni.service.TimeService.java

public LocalDateTime weekAgo() {
    return LocalDateTime.now().minusWeeks(1);
}

From source file:net.resheim.eclipse.timekeeper.internal.TaskActivationListener.java

@Override
public void preTaskActivated(ITask task) {
    LocalDateTime now = LocalDateTime.now();
    String startString = Activator.getValue(task, Activator.START);
    String tickString = Activator.getValue(task, Activator.TICK);
    if (startString != null) {
        LocalDateTime ticked = LocalDateTime.parse(tickString);
        LocalDateTime stopped = LocalDateTime.now();
        long seconds = ticked.until(stopped, ChronoUnit.SECONDS);
        String time = DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true);
        boolean confirm = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Add elapsed time?",
                "Work was already started and task was last updated on "
                        + ticked.format(DateTimeFormatter.ofPattern("EEE e, HH:mm", Locale.US))
                        + ". Continue and add the elapsed time since (" + time + ") to the task total?");
        if (confirm) {
            Activator.accumulateTime(task, startString, ticked.until(LocalDateTime.now(), ChronoUnit.MILLIS));
        }/*from www  .  j  a  v a  2 s.c  o m*/
    }
    Activator.setValue(task, Activator.TICK, now.toString());
    Activator.setValue(task, Activator.START, now.toString());
}

From source file:my.school.spring.rest.controllers.ScheduledVersionDataProviderImpl.java

@Scheduled(cron = "0 1/3 * * * *")
public void testSchedule() {
    logTime(LocalDateTime.now());
}

From source file:cz.muni.fi.editor.services.api.notifications.NotificationFactoryImpl.java

@Override
public Notification provideNotification(EditorEvent editorEvent) {
    Notification n = new Notification();
    n.setNotificationDate(LocalDateTime.now());
    switch (editorEvent.getType()) {
    case 1: {//from  w w  w .  j  a  v a 2  s .  c  o m
        EOrganizationDisbanded disbanded = (EOrganizationDisbanded) editorEvent;
        n.setMessage(MessageFormat.format(editorEvent.getNotificationMessage(), disbanded.getName()));
    }
        break;
    case 2: {
        EOrganizationInvited invited = (EOrganizationInvited) editorEvent;
        n.setMessage(MessageFormat.format(editorEvent.getNotificationMessage(),
                invited.getOrganization().getOrganizationName()));
        n.setNotified(invited.getUser());
    }
        break;
    case 3: {

    }
        break;
    case 4: {
        EOrganizationKicked kicked = (EOrganizationKicked) editorEvent;
        n.setMessage(MessageFormat.format(editorEvent.getNotificationMessage(),
                kicked.getOrganization().getOrganizationName()));
        n.setNotified(kicked.getUser());
    }
        break;
    case 5: {
        EOrganizationPromoted promoted = (EOrganizationPromoted) editorEvent;
        n.setMessage(MessageFormat.format(editorEvent.getNotificationMessage(),
                promoted.getOrganization().getOrganizationName()));
        n.setNotified(promoted.getOrganization().getOwner());
    }
        break;
    case 6: {
        EOrganizationRenamed renamed = (EOrganizationRenamed) editorEvent;
        n.setMessage(MessageFormat.format(editorEvent.getNotificationMessage(), renamed.getOriginalName(),
                renamed.getOrganization().getOrganizationName()));
    }
        break;
    case 7: {
        ERequestApproved approved = (ERequestApproved) editorEvent;
        n.setMessage(MessageFormat.format(editorEvent.getNotificationMessage(),
                requestToParameter(approved.getRequest())));
        n.setRequest(approved.getRequest());
        n.setNotified(approved.getRequest().getRequestor());
    }
        break;
    case 8: {
        ERequestCreated created = (ERequestCreated) editorEvent;
        n.setRequest(created.getRequest());
        n.setMessage(MessageFormat.format(editorEvent.getNotificationMessage(),
                requestToParameter(created.getRequest())));
    }
        break;
    case 9: {
        ERequestDenied denied = (ERequestDenied) editorEvent;
        n.setRequest(denied.getRequest());
        n.setMessage(MessageFormat.format(editorEvent.getNotificationMessage(),
                requestToParameter(denied.getRequest())));
    }
        break;
    default:
        throw new IllegalArgumentException(MessageFormat
                .format("Invalid event type. Type cannot be greater than {0}", EditorEvent.types.length - 1));
    }

    return n;
}