Kotlin get date for tomorrow only
up vote
1
down vote
favorite
I need to display tomorrow's date only , l have this code and his working fine without problem . and he is give the current date for today. l want change this code to get the date for tomorrow but l dont know how !
private fun date24hours(s: String): String? {
try {
val sdf = SimpleDateFormat("EE, MMM d, yyy")
val netDate = Date(s.toLong() * 1000)
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
date kotlin
add a comment |
up vote
1
down vote
favorite
I need to display tomorrow's date only , l have this code and his working fine without problem . and he is give the current date for today. l want change this code to get the date for tomorrow but l dont know how !
private fun date24hours(s: String): String? {
try {
val sdf = SimpleDateFormat("EE, MMM d, yyy")
val netDate = Date(s.toLong() * 1000)
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
date kotlin
Does the argument string hold seconds since the epoch? If you just want tomorrow’s date, this seems to be the detour.
– Ole V.V.
1 hour ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to display tomorrow's date only , l have this code and his working fine without problem . and he is give the current date for today. l want change this code to get the date for tomorrow but l dont know how !
private fun date24hours(s: String): String? {
try {
val sdf = SimpleDateFormat("EE, MMM d, yyy")
val netDate = Date(s.toLong() * 1000)
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
date kotlin
I need to display tomorrow's date only , l have this code and his working fine without problem . and he is give the current date for today. l want change this code to get the date for tomorrow but l dont know how !
private fun date24hours(s: String): String? {
try {
val sdf = SimpleDateFormat("EE, MMM d, yyy")
val netDate = Date(s.toLong() * 1000)
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
date kotlin
date kotlin
asked 7 hours ago
pabloescobar
688
688
Does the argument string hold seconds since the epoch? If you just want tomorrow’s date, this seems to be the detour.
– Ole V.V.
1 hour ago
add a comment |
Does the argument string hold seconds since the epoch? If you just want tomorrow’s date, this seems to be the detour.
– Ole V.V.
1 hour ago
Does the argument string hold seconds since the epoch? If you just want tomorrow’s date, this seems to be the detour.
– Ole V.V.
1 hour ago
Does the argument string hold seconds since the epoch? If you just want tomorrow’s date, this seems to be the detour.
– Ole V.V.
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
It is possible to use Date
for this, but Java 8 LocalDate
is a lot easier to work with:
// Set up our formatter with a custom pattern
val formatter = DateTimeFormatter.ofPattern("EE, MMM d, yyy")
// Parse our string with our custom formatter
var parsedDate = LocalDate.parse(s, formatter)
// Simply plus 1 day to make it tomorrows date
parsedDate = parsedDate.plusDays(1)
2
LocalDate
is immutable, so the last line will not do anything on its own
– Moira
6 hours ago
@Moira good spot, thanks for updating
– Eamon Scullion
6 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
It is possible to use Date
for this, but Java 8 LocalDate
is a lot easier to work with:
// Set up our formatter with a custom pattern
val formatter = DateTimeFormatter.ofPattern("EE, MMM d, yyy")
// Parse our string with our custom formatter
var parsedDate = LocalDate.parse(s, formatter)
// Simply plus 1 day to make it tomorrows date
parsedDate = parsedDate.plusDays(1)
2
LocalDate
is immutable, so the last line will not do anything on its own
– Moira
6 hours ago
@Moira good spot, thanks for updating
– Eamon Scullion
6 hours ago
add a comment |
up vote
2
down vote
It is possible to use Date
for this, but Java 8 LocalDate
is a lot easier to work with:
// Set up our formatter with a custom pattern
val formatter = DateTimeFormatter.ofPattern("EE, MMM d, yyy")
// Parse our string with our custom formatter
var parsedDate = LocalDate.parse(s, formatter)
// Simply plus 1 day to make it tomorrows date
parsedDate = parsedDate.plusDays(1)
2
LocalDate
is immutable, so the last line will not do anything on its own
– Moira
6 hours ago
@Moira good spot, thanks for updating
– Eamon Scullion
6 hours ago
add a comment |
up vote
2
down vote
up vote
2
down vote
It is possible to use Date
for this, but Java 8 LocalDate
is a lot easier to work with:
// Set up our formatter with a custom pattern
val formatter = DateTimeFormatter.ofPattern("EE, MMM d, yyy")
// Parse our string with our custom formatter
var parsedDate = LocalDate.parse(s, formatter)
// Simply plus 1 day to make it tomorrows date
parsedDate = parsedDate.plusDays(1)
It is possible to use Date
for this, but Java 8 LocalDate
is a lot easier to work with:
// Set up our formatter with a custom pattern
val formatter = DateTimeFormatter.ofPattern("EE, MMM d, yyy")
// Parse our string with our custom formatter
var parsedDate = LocalDate.parse(s, formatter)
// Simply plus 1 day to make it tomorrows date
parsedDate = parsedDate.plusDays(1)
edited 6 hours ago
Moira
5,08021635
5,08021635
answered 6 hours ago
Eamon Scullion
638313
638313
2
LocalDate
is immutable, so the last line will not do anything on its own
– Moira
6 hours ago
@Moira good spot, thanks for updating
– Eamon Scullion
6 hours ago
add a comment |
2
LocalDate
is immutable, so the last line will not do anything on its own
– Moira
6 hours ago
@Moira good spot, thanks for updating
– Eamon Scullion
6 hours ago
2
2
LocalDate
is immutable, so the last line will not do anything on its own– Moira
6 hours ago
LocalDate
is immutable, so the last line will not do anything on its own– Moira
6 hours ago
@Moira good spot, thanks for updating
– Eamon Scullion
6 hours ago
@Moira good spot, thanks for updating
– Eamon Scullion
6 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371132%2fkotlin-get-date-for-tomorrow-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Does the argument string hold seconds since the epoch? If you just want tomorrow’s date, this seems to be the detour.
– Ole V.V.
1 hour ago