Questions tagged [localtime]

Calendar time expressed relative to the user's local timezone.

Calendar time expressed relative to the user's local timezone.

461 questions
16
votes
4 answers

LocalTime between 23.59 and 00:01

I want to check if a LocalTime is midnight. For this use case midnight is defined as anything in between 23:59 and 00:01. That is a range of 2 minutes. private final LocalTime ONE_MINUTE_BEFORE_MIDNIGHT = LocalTime.of(23, 59, 0); private final…
isADon
  • 3,433
  • 11
  • 35
  • 49
16
votes
2 answers

Globally convert UTC DateTimes to user specified local DateTimes

I am storing all the DateTime fields as UTC time. When a user requests a web page, I would like to take his preferred local timezone (and not the local timezone of the server machine) and automatically display all the DateTime fields in all the web…
JustAMartin
  • 13,165
  • 18
  • 99
  • 183
15
votes
3 answers

C++ - 'localtime' this function or variable may be unsafe

I am writing a simple logging class in C++ for learning purposes. My code contains a function that returns a string of today's date. However, I get a compiler error whenever 'localtime' is called. std::string get_date_string(time_t *time) { …
ChiefHagno
  • 168
  • 1
  • 1
  • 7
15
votes
1 answer

how to use localtime_s with a pointer in c++

I am working with a function in C++ to help get the integer for the month. I did some searching and found one that uses localtime but I do not want to set it up to remove warnings so I need to use localtime_s. but when I use that my pointer no…
kevin haysmer
  • 171
  • 1
  • 1
  • 5
14
votes
8 answers

How do I get yesterday's date using localtime?

How do I tweak this to get yesterday's date using localtime? use strict; sub spGetCurrentDateTime; print spGetCurrentDateTime; sub spGetCurrentDateTime { my ($sec, $min, $hour, $mday, $mon, $year) = localtime(); my @abbr = qw( Jan Feb Mar Apr May…
jdamae
  • 3,839
  • 16
  • 58
  • 78
13
votes
6 answers

Get current date time from server and convert it into local time in c#

Help: I have a server which is having time in GMT-07.00 hours. My local time is GMT+05.30 hours. I need to get current date and time from server and convert this date and time into my local time. I have tried many codes, but still have not found a…
njnjnj
  • 978
  • 4
  • 23
  • 58
12
votes
9 answers

Joda Time LocalTime of 24:00 end-of-day

We're creating a scheduling application and we need to represent someone's available schedule during the day, regardless of what time zone they are in. Taking a cue from Joda Time's Interval, which represents an interval in absolute time between two…
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
12
votes
3 answers

Make Python respond to Windows timezone changes

When Python is running under Windows, time.localtime does not report the correct time if the timezone is changed during the life time of the Python instance. Under Linux, time.tzset can always been run to alleviate problems like this, but there…
Eric Pruitt
  • 1,825
  • 3
  • 21
  • 34
12
votes
2 answers

Confusion with Java Time parsing UTC

I am confused with time handling in java time. I so long worked under the assumption that if a timestamp is specified as a zulu time, java would take care of the offset with regards to local time. To illustrate. I am currently in BST which has an…
pandaadb
  • 6,306
  • 2
  • 22
  • 41
12
votes
3 answers

between java.time.LocalTime (next day)

Please suggest if there is an API support to determine if my time is between 2 LocalTime instances, or suggest a different approach. I have this entity: class Place { LocalTime startDay; LocalTime endDay; } which stores the working day…
Andrii Karaivanskyi
  • 1,942
  • 3
  • 19
  • 23
12
votes
1 answer

Real-time awareness of timezone change in localtime() vs localtime_r()

Working on an Ubuntu 12.04.3 LTS box, I just noticed that localtime() and localtime_r() behave differently when the system's timezone changes during the lifetime of a process: localtime() picks up the timezone change immediately, whereas…
Christian
  • 1,499
  • 2
  • 12
  • 28
11
votes
2 answers

LocalTime() difference between two times

I have a flight itinerary program where I need to get difference between departure and arrival time. I get these specified times as String from the data. Here is my problem: import static java.time.temporal.ChronoUnit.MINUTES; import…
Naeem Khan
  • 950
  • 4
  • 13
  • 34
10
votes
1 answer

Why is it so convoluted to get the date and/or time in C++?

I fully expect this to be closed within a day or two since it's a kinda subjective topic, but here goes anyway: Why does it take at least 5 lines of code to get the date/time in C++? This was one of the first things I learnt how to do in C, but that…
Kenny83
  • 769
  • 12
  • 38
10
votes
4 answers

Swift: NSDate formatting with strftime & localtime

How do I convert the following Objective-C code into Swift code? #define MAX_SIZE 11 char buffer[MAX_SIZE]; time_t time = [[NSDate date] timeIntervalSince1970]; strftime(buffer, MAX_SIZE, "%-l:%M\u2008%p", localtime(&time)); NSString *dateString =…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
9
votes
6 answers

Failed to parse single digit hour and lowercase am-pm of day into Java 8 LocalTime

When I try to run the following code: LocalTime test = LocalTime.parse("8:00am", DateTimeFormatter.ofPattern("hh:mma")); I get this: Exception in thread "main" java.time.format.DateTimeParseException: Text '8:00am' could not be parsed at index…
benstpierre
  • 32,833
  • 51
  • 177
  • 288
1
2
3
30 31