01-03-2022 07:41 AM
I want to get current date in scala as a string for example today current date is 3rd jan, want to store it as a new variable dynamically as below, how to get it.
val currdate : String = “20220103”
when I am using val currdate = Calendar.getInstance.getTime then am not getting output in desired format as above.
01-03-2022 03:20 PM
@Vibhor Sethi - Thanks for your question. We will circle back around if the other members don't reply first. Thanks in advance for your patience.
01-04-2022 09:43 PM
Hi thanks. Could you please circle back around the question.
01-05-2022 08:36 AM
@Vibhor Sethi - I'll pass this on to the team. Thank you. 🙂
01-07-2022 08:52 AM
Hi @Vibhor Sethi ,
This is how it's done using contemporary java.time library.
import java.time.LocalDate
import java.time.format.DateTimeFormatter
val currdate:String =
LocalDate.now.format(DateTimeFormatter.ofPattern("yyyyMMdd"))
Older utilities like Calendar and SimpleDate still work (mostly) but should be avoided.
01-08-2022 11:46 AM
Thanks it worked
01-08-2022 12:48 PM
Hi @Vibhor Sethi , Would you like to mark it as the best answer?
06-03-2022 08:25 AM
Hey @Vibhor Sethi
Hope you are well!
Thank you for posting your question and letting us know that you were able to resolve the issue. Would you be happy to mark it as the best solution? It would be really helpful for the other members too.
Cheers!
Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections.
Click here to register and join today!
Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.