Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,471 members, 7,808,696 topics. Date: Thursday, 25 April 2024 at 03:33 PM |
Nairaland Forum / Science/Technology / Programming / Convert This Java To Dotnet Very Urgent (2129 Views)
I Want To Develop A Software In Java To Calculate CGPA / What Topics To Cover In Java To Be A Guru? / Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl (2) (3) (4)
Convert This Java To Dotnet Very Urgent by luckyCO(m): 5:12pm On Jan 14, 2011 |
public static String toDate(Date d) { Calendar calendar = Calendar.getInstance(); calendar.setTime(d); calendar.add(Calendar.MONTH, 1); calendar.add(Calendar.DAY_OF_MONTH, 1); String fieldDate = calendar.get(Calendar.DAY_OF_MONTH) + "/" + (calendar.get(Calendar.MONTH)) + "/" + calendar.get(Calendar.YEAR); return fieldDate; } public static String toDate(long d) { Date date = new Date(d); return Resources.toDate(date); } |
Re: Convert This Java To Dotnet Very Urgent by dazz4me: 10:11pm On Jan 14, 2011 |
I have never read or write java before so i don't know if i'm correct. if ok you can easily convert to C# Public Shared Function toDate(ByVal d As Date) As String Dim fieldDate As String = "" d.AddMonths(1) d.AddDays(1) fieldDate = d.ToString("d") Return fieldDate End Function Public Shared Function toDate(ByVal d As Long) As String Dim _date As Date = New Date(d) Return toDate(_date) End Function |
Re: Convert This Java To Dotnet Very Urgent by luckyCO(m): 2:10am On Jan 15, 2011 |
I even did more than that and converted exactly how java did but was giving me another thing Look at the code below import java.util.Calendar; import java.util.Date; public class NewClass { public static String toDate(Date d) { Calendar calendar = Calendar.getInstance(); calendar.setTime(d); calendar.add(Calendar.MONTH, 1); calendar.add(Calendar.DAY_OF_MONTH, 1); String fieldDate = calendar.get(Calendar.DAY_OF_MONTH) + "/" + (calendar.get(Calendar.MONTH)) + "/" + calendar.get(Calendar.YEAR); return fieldDate; } public static String toDate(long d) { Date date = new Date(d); return NewClass.toDate(date); } } I consume the class long mydate=1149617771796l; Date d = new Date(mydate); System.out.println("today = " + d); I got "today = Tue Jun 06 18:16:11 GMT 2006" In dotnet I did the same thing as below private function toDate( d as long) as string Dim sdate As New Date(d) return sdate end function I Consume it with dim mydate as long =1149617771796l; console.writeln todate(mydate )) I got "1/2/1" Why |
Re: Convert This Java To Dotnet Very Urgent by Mobinga: 11:50am On Jan 15, 2011 |
dazz4me: Shame on you. |
Re: Convert This Java To Dotnet Very Urgent by Beaf: 6:47am On Jan 16, 2011 |
I've simply typed in all of this, so there might be a couple of syntax errors (I doubt it though). I've given three ways to do it, from the worst to the best. Enjoy. 1. This is a direct C# translation of your java code that will do what you want, but is the wrong way to write it. using System; 2. This is a better way (not the best though): using System; 3. If you find yourself getting hammered with the wrong dates, its likely that you are being hit by globalisation / localisation issues; the system running the code is running on could be in a different time zone to what you expect, or it could be in a different locale. This is the proper way to kill that scenario. using System; |
(1) (Reply)
[Advice] Please How do I become a Programmer? / How To Change Your Facebook Display Name / Meet The 19-year-old Who Built A New Search Engine To Rival Google And Youtube
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 16 |