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()









share|improve this question






















  • 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

















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()









share|improve this question






















  • 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















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()









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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




















  • 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














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)





share|improve this answer



















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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)





share|improve this answer



















  • 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















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)





share|improve this answer



















  • 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













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)





share|improve this answer














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)






share|improve this answer














share|improve this answer



share|improve this answer








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














  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules