Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii guys i have a value which is in int64 value i need to convert it into date
my reference code which is in java
else
                {
                    String dateString = DateFormat.format("dd/MM/yyyy", new Date(Item.CompletedDate*1000)).toString();
                    textView_completeddate.setText(dateString);
                }

i neeed this to convert into c#

What I have tried:

my code is
else
                   {
                       DateTime dateTime= new DateTime(item.CompletedDate);
                          var date = dateTime.ToString("MM/dd/yyyy");

                       string result = date.ToString();
                   }

the value will be in
1605584420
Posted
Updated 2-Jan-23 23:55pm
Comments
Richard MacCutchan 3-Jan-23 5:14am    
What is the problem?
alisa brigita 3-Jan-23 5:23am    
i can,t get the correct date

The Java Date constructor you are using expects milliseconds since January 1, 1970, 00:00:00 GMT - C# works in Ticks which aren't the same at all: Date (Java Platform SE 8 )[^]

I'd construct a DateTime object at Jan 1 1970, then use the DateTime.AddMilliseconds(Double) Method (System) | Microsoft Learn[^] method to convert your Java value to C#.
 
Share this answer
 
Comments
alisa brigita 3-Jan-23 6:25am    
its not working
OriginalGriff 3-Jan-23 6:56am    
"its not working" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.

Perhaps show us the exact code you used as well?
Your value for conversion is not correct. The following code returns today's date in ticks as specified at DateTime Constructor (System) | Microsoft Learn[^].
C#
DateTime dateTime = DateTime.Now;
var ticks = dateTime.Ticks;
Console.WriteLine($"dateTime: {ticks}");

And the result is:
dateTime: 638083380629232554
 
Share this answer
 
Comments
alisa brigita 3-Jan-23 6:24am    
i need only the date in date formate dd/MM/yyyy
Richard MacCutchan 3-Jan-23 6:31am    
Well you still need to start with a valid number to make a valid date.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900