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
415
votes
26 answers

How to convert local time string to UTC?

How do I convert a datetime string in local time to a string in UTC time? I'm sure I've done this before, but can't find it and SO will hopefully help me (and others) do that in future. Clarification: For example, if I have 2008-09-17 14:02:00 in…
Tom
  • 42,844
  • 35
  • 95
  • 101
311
votes
16 answers

Convert UTC datetime string to local datetime

I've never had to convert time to and from UTC. Recently had a request to have my app be timezone aware, and I've been running myself in circles. Lots of information on converting local time to UTC, which I found fairly elementary (maybe I'm doing…
MattoTodd
  • 14,467
  • 16
  • 59
  • 76
184
votes
3 answers

How to convert java.sql.timestamp to LocalDate (java8) java.time?

In Java 8, how can I convert a Timestamp (in java.sql) to a LocalDate (in java.time)?
simonides
  • 3,040
  • 3
  • 19
  • 34
130
votes
11 answers

Get the current time in C

I want to get the current time of my system. For that I'm using the following code in C: time_t now; struct tm *mytime = localtime(&now); if ( strftime(buffer, sizeof buffer, "%X", mytime) ) { printf("time1 = \"%s\"\n", buffer); } The problem…
Antrromet
  • 15,294
  • 10
  • 60
  • 75
63
votes
3 answers

How to Convert UTC Date To Local time Zone in MySql Select Query

I am using this Where Condition in One Of my query with MySql Database.My Problem is that i have one displaytime column in my table but that table column shows the data in UTC Time.and i want to convert that displaytime column in the Local Time…
BhavikKama
  • 8,566
  • 12
  • 94
  • 164
55
votes
3 answers

localtime vs localtime_s and appropriate input arguments

time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); This returns: warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. time_t rawtime; struct tm *…
ProGirlXOXO
  • 2,170
  • 6
  • 25
  • 47
53
votes
11 answers

Get the Olson TZ name for the local timezone?

How do I get the Olson timezone name (such as Australia/Sydney) corresponding to the value given by C's localtime call? This is the value overridden via TZ, by symlinking /etc/localtime, or setting a TIMEZONE variable in time-related system…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
50
votes
4 answers

Java subtract LocalTime

I have two LocalTime objects: LocalTime l1 = LocalTime.parse("02:53:40"); LocalTime l2 = LocalTime.parse("02:54:27"); How can I found different in minutes between them?
Bob
  • 10,427
  • 24
  • 63
  • 71
37
votes
6 answers

How to fix "Call requires API level 26 (current min is 25) " error in Android

I know this question may be duplicated but I didn't find any answer for my problem, I'm using LocalDateTime in my Android app that requires API 26 and my device's API is 25. What can I do? Your help will be very appreciated.
Anna
  • 383
  • 1
  • 3
  • 4
37
votes
6 answers

How to remove milliseconds from LocalTime in java 8

Using the java.time framework, I want to print time in format hh:mm:ss, but LocalTime.now() gives the time in the format hh:mm:ss,nnn. I tried to use DateTimeFormatter: DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_TIME; LocalTime time =…
Nikolas
  • 2,322
  • 9
  • 33
  • 55
22
votes
5 answers

Formatting local time in java

I'm creating my JavaFX application and I need to use time label every time new list cell is created. I need to put the string with current time in HH:MM format directly into Label constructor which takes String as a parameter. I found and used…
Daniel Piskorz
  • 390
  • 1
  • 2
  • 11
18
votes
1 answer

LocalTime.MIDNIGHT vs. LocalTime.MIN - is there any difference?

I recently answered some questions using LocalDate.atStartOfDay() and LocalDate.atTime(LocalTime.MIN). I was wondering why there is no LocalDate.atEndOfDay() or similar, so one has to use LocalDate.atTime(LocalTime.MAX) in order to get the very last…
deHaar
  • 17,687
  • 10
  • 38
  • 51
18
votes
2 answers

Coverting String to LocalTime with/without nanoOfSeconds

I need to convert a string to LocalTime (java-8 not joda) that may or maynot have nanoOfSeconds in the string. The String format is in the form of 07:06:05 or 07:06:05.123456 The string may or may not have a decimal place in the seconds and…
jbolt
  • 688
  • 3
  • 16
  • 37
18
votes
5 answers

LocalTime from Date

I'm trying to convert a Date instance to a LocalTime instance. // Create the Date Date date = format.parse("2011-02-18 05:00:00.0"); // Convert to Calendar Calendar cal = Calendar.getInstance(); cal.setTime(date); // Convert Calendar to…
Stanko
  • 4,275
  • 3
  • 23
  • 51
16
votes
4 answers

C++: how to get the actual time with time and localtime?

I'm looking for a way to save the time in a HH::MM::SS fashion in C++. I saw here that they are many solutions and after a little research I opted for time and localtime. However, it seems like the localtime function is a little tricky, since it…
seb
  • 2,136
  • 3
  • 20
  • 27
1
2 3
30 31