Kotlin convert TimeStamp to DateTime
I'm trying to find out how I can convert timestamp
to datetime
in Kotlin, this is very simple in Java but I cant find any equivalent of it in Kotlin.
For example: epoch timestamp (seconds since 1070-01-01) 1510500494
==> DateTime object 2017-11-12 03:28:14
.
Is there any solution for this in Kotlin or do I have to use Java syntax in Kotlin? Please give me a simple sample to show how I can resolve this problem. Thanks in advance.
this link is not an answer to my question
java kotlin timestamp
|
show 5 more comments
I'm trying to find out how I can convert timestamp
to datetime
in Kotlin, this is very simple in Java but I cant find any equivalent of it in Kotlin.
For example: epoch timestamp (seconds since 1070-01-01) 1510500494
==> DateTime object 2017-11-12 03:28:14
.
Is there any solution for this in Kotlin or do I have to use Java syntax in Kotlin? Please give me a simple sample to show how I can resolve this problem. Thanks in advance.
this link is not an answer to my question
java kotlin timestamp
sorry for that I've remove the flag .
– moath naji
Nov 12 '17 at 15:08
@moathnaji i'm trying to convert timestamp not UTC
– DolDurma
Nov 12 '17 at 15:10
You should provide the Java code you would use that is "very simple" to make it easier for someone to show you the Kotlin equivalent.
– dominicoder
Nov 12 '17 at 15:15
2
That's not what I'm suggesting. I'm just suggesting you ask IntelliJ to convert the Java code to Kotlin. But if you're not familiar with Kotlin, why don't you become familiar with it before using Kotlin? And you still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:00
2
That is irrelevant. You still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:08
|
show 5 more comments
I'm trying to find out how I can convert timestamp
to datetime
in Kotlin, this is very simple in Java but I cant find any equivalent of it in Kotlin.
For example: epoch timestamp (seconds since 1070-01-01) 1510500494
==> DateTime object 2017-11-12 03:28:14
.
Is there any solution for this in Kotlin or do I have to use Java syntax in Kotlin? Please give me a simple sample to show how I can resolve this problem. Thanks in advance.
this link is not an answer to my question
java kotlin timestamp
I'm trying to find out how I can convert timestamp
to datetime
in Kotlin, this is very simple in Java but I cant find any equivalent of it in Kotlin.
For example: epoch timestamp (seconds since 1070-01-01) 1510500494
==> DateTime object 2017-11-12 03:28:14
.
Is there any solution for this in Kotlin or do I have to use Java syntax in Kotlin? Please give me a simple sample to show how I can resolve this problem. Thanks in advance.
this link is not an answer to my question
java kotlin timestamp
java kotlin timestamp
edited Dec 13 '18 at 18:14
t0r0X
1,8721620
1,8721620
asked Nov 12 '17 at 15:01
DolDurmaDolDurma
3,3841266136
3,3841266136
sorry for that I've remove the flag .
– moath naji
Nov 12 '17 at 15:08
@moathnaji i'm trying to convert timestamp not UTC
– DolDurma
Nov 12 '17 at 15:10
You should provide the Java code you would use that is "very simple" to make it easier for someone to show you the Kotlin equivalent.
– dominicoder
Nov 12 '17 at 15:15
2
That's not what I'm suggesting. I'm just suggesting you ask IntelliJ to convert the Java code to Kotlin. But if you're not familiar with Kotlin, why don't you become familiar with it before using Kotlin? And you still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:00
2
That is irrelevant. You still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:08
|
show 5 more comments
sorry for that I've remove the flag .
– moath naji
Nov 12 '17 at 15:08
@moathnaji i'm trying to convert timestamp not UTC
– DolDurma
Nov 12 '17 at 15:10
You should provide the Java code you would use that is "very simple" to make it easier for someone to show you the Kotlin equivalent.
– dominicoder
Nov 12 '17 at 15:15
2
That's not what I'm suggesting. I'm just suggesting you ask IntelliJ to convert the Java code to Kotlin. But if you're not familiar with Kotlin, why don't you become familiar with it before using Kotlin? And you still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:00
2
That is irrelevant. You still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:08
sorry for that I've remove the flag .
– moath naji
Nov 12 '17 at 15:08
sorry for that I've remove the flag .
– moath naji
Nov 12 '17 at 15:08
@moathnaji i'm trying to convert timestamp not UTC
– DolDurma
Nov 12 '17 at 15:10
@moathnaji i'm trying to convert timestamp not UTC
– DolDurma
Nov 12 '17 at 15:10
You should provide the Java code you would use that is "very simple" to make it easier for someone to show you the Kotlin equivalent.
– dominicoder
Nov 12 '17 at 15:15
You should provide the Java code you would use that is "very simple" to make it easier for someone to show you the Kotlin equivalent.
– dominicoder
Nov 12 '17 at 15:15
2
2
That's not what I'm suggesting. I'm just suggesting you ask IntelliJ to convert the Java code to Kotlin. But if you're not familiar with Kotlin, why don't you become familiar with it before using Kotlin? And you still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:00
That's not what I'm suggesting. I'm just suggesting you ask IntelliJ to convert the Java code to Kotlin. But if you're not familiar with Kotlin, why don't you become familiar with it before using Kotlin? And you still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:00
2
2
That is irrelevant. You still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:08
That is irrelevant. You still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:08
|
show 5 more comments
4 Answers
4
active
oldest
votes
private fun getDateTime(s: String): String? {
try {
val sdf = SimpleDateFormat("MM/dd/yyyy")
val netDate = Date(Long.parseLong(s))
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
}
}
val netDate = Date(s.toLong() * 1000) worked for me.
– temp_
Feb 22 '18 at 17:43
Is this to current locale?
– JGuo
Jul 27 '18 at 14:13
add a comment |
It's actually just like Java. Try this:
val stamp = Timestamp(System.currentTimeMillis())
val date = Date(stamp.getTime())
println(date)
add a comment |
Although it's Kotlin, you still have to use the Java API. An example for Java 8+ APIs converting the value 1510500494
which you mentioned in the question comments:
import java.time.*
val dt = Instant.ofEpochSecond(1510500494).atZone(ZoneId.systemDefault()).toLocalDateTime()
add a comment |
fun stringtoDate(dates: String): Date {
val sdf = SimpleDateFormat("EEE, MMM dd yyyy",
Locale.ENGLISH)
var date: Date? = null
try {
date = sdf.parse(dates)
println(date)
} catch (e: ParseException) {
e.printStackTrace()
}
return date!!
}
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f47250263%2fkotlin-convert-timestamp-to-datetime%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
private fun getDateTime(s: String): String? {
try {
val sdf = SimpleDateFormat("MM/dd/yyyy")
val netDate = Date(Long.parseLong(s))
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
}
}
val netDate = Date(s.toLong() * 1000) worked for me.
– temp_
Feb 22 '18 at 17:43
Is this to current locale?
– JGuo
Jul 27 '18 at 14:13
add a comment |
private fun getDateTime(s: String): String? {
try {
val sdf = SimpleDateFormat("MM/dd/yyyy")
val netDate = Date(Long.parseLong(s))
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
}
}
val netDate = Date(s.toLong() * 1000) worked for me.
– temp_
Feb 22 '18 at 17:43
Is this to current locale?
– JGuo
Jul 27 '18 at 14:13
add a comment |
private fun getDateTime(s: String): String? {
try {
val sdf = SimpleDateFormat("MM/dd/yyyy")
val netDate = Date(Long.parseLong(s))
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
}
}
private fun getDateTime(s: String): String? {
try {
val sdf = SimpleDateFormat("MM/dd/yyyy")
val netDate = Date(Long.parseLong(s))
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
}
}
answered Nov 13 '17 at 9:48
arjun shresthaarjun shrestha
461210
461210
val netDate = Date(s.toLong() * 1000) worked for me.
– temp_
Feb 22 '18 at 17:43
Is this to current locale?
– JGuo
Jul 27 '18 at 14:13
add a comment |
val netDate = Date(s.toLong() * 1000) worked for me.
– temp_
Feb 22 '18 at 17:43
Is this to current locale?
– JGuo
Jul 27 '18 at 14:13
val netDate = Date(s.toLong() * 1000) worked for me.
– temp_
Feb 22 '18 at 17:43
val netDate = Date(s.toLong() * 1000) worked for me.
– temp_
Feb 22 '18 at 17:43
Is this to current locale?
– JGuo
Jul 27 '18 at 14:13
Is this to current locale?
– JGuo
Jul 27 '18 at 14:13
add a comment |
It's actually just like Java. Try this:
val stamp = Timestamp(System.currentTimeMillis())
val date = Date(stamp.getTime())
println(date)
add a comment |
It's actually just like Java. Try this:
val stamp = Timestamp(System.currentTimeMillis())
val date = Date(stamp.getTime())
println(date)
add a comment |
It's actually just like Java. Try this:
val stamp = Timestamp(System.currentTimeMillis())
val date = Date(stamp.getTime())
println(date)
It's actually just like Java. Try this:
val stamp = Timestamp(System.currentTimeMillis())
val date = Date(stamp.getTime())
println(date)
answered Mar 29 '18 at 20:19
Javier García ManzanoJavier García Manzano
253213
253213
add a comment |
add a comment |
Although it's Kotlin, you still have to use the Java API. An example for Java 8+ APIs converting the value 1510500494
which you mentioned in the question comments:
import java.time.*
val dt = Instant.ofEpochSecond(1510500494).atZone(ZoneId.systemDefault()).toLocalDateTime()
add a comment |
Although it's Kotlin, you still have to use the Java API. An example for Java 8+ APIs converting the value 1510500494
which you mentioned in the question comments:
import java.time.*
val dt = Instant.ofEpochSecond(1510500494).atZone(ZoneId.systemDefault()).toLocalDateTime()
add a comment |
Although it's Kotlin, you still have to use the Java API. An example for Java 8+ APIs converting the value 1510500494
which you mentioned in the question comments:
import java.time.*
val dt = Instant.ofEpochSecond(1510500494).atZone(ZoneId.systemDefault()).toLocalDateTime()
Although it's Kotlin, you still have to use the Java API. An example for Java 8+ APIs converting the value 1510500494
which you mentioned in the question comments:
import java.time.*
val dt = Instant.ofEpochSecond(1510500494).atZone(ZoneId.systemDefault()).toLocalDateTime()
answered Nov 13 '18 at 15:02
t0r0Xt0r0X
1,8721620
1,8721620
add a comment |
add a comment |
fun stringtoDate(dates: String): Date {
val sdf = SimpleDateFormat("EEE, MMM dd yyyy",
Locale.ENGLISH)
var date: Date? = null
try {
date = sdf.parse(dates)
println(date)
} catch (e: ParseException) {
e.printStackTrace()
}
return date!!
}
add a comment |
fun stringtoDate(dates: String): Date {
val sdf = SimpleDateFormat("EEE, MMM dd yyyy",
Locale.ENGLISH)
var date: Date? = null
try {
date = sdf.parse(dates)
println(date)
} catch (e: ParseException) {
e.printStackTrace()
}
return date!!
}
add a comment |
fun stringtoDate(dates: String): Date {
val sdf = SimpleDateFormat("EEE, MMM dd yyyy",
Locale.ENGLISH)
var date: Date? = null
try {
date = sdf.parse(dates)
println(date)
} catch (e: ParseException) {
e.printStackTrace()
}
return date!!
}
fun stringtoDate(dates: String): Date {
val sdf = SimpleDateFormat("EEE, MMM dd yyyy",
Locale.ENGLISH)
var date: Date? = null
try {
date = sdf.parse(dates)
println(date)
} catch (e: ParseException) {
e.printStackTrace()
}
return date!!
}
answered Jul 18 '18 at 5:14
Umesh MaharjanUmesh Maharjan
1763
1763
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f47250263%2fkotlin-convert-timestamp-to-datetime%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
sorry for that I've remove the flag .
– moath naji
Nov 12 '17 at 15:08
@moathnaji i'm trying to convert timestamp not UTC
– DolDurma
Nov 12 '17 at 15:10
You should provide the Java code you would use that is "very simple" to make it easier for someone to show you the Kotlin equivalent.
– dominicoder
Nov 12 '17 at 15:15
2
That's not what I'm suggesting. I'm just suggesting you ask IntelliJ to convert the Java code to Kotlin. But if you're not familiar with Kotlin, why don't you become familiar with it before using Kotlin? And you still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:00
2
That is irrelevant. You still haven't posted the very simple Java code.
– JB Nizet
Nov 12 '17 at 16:08