-3

im getting incorrect time in the remote server.i'm getting the correct datetime in the local system.our server may be in other country, how to get correct datetime which is im getting in the local system.

Local application date time - 23/05/2018 06:40:20 PM

time after deploy in server - 23/05/2018 09:10:20 AM

timestamp - 2018-05-23T10:56:12.730Z

getting output

23/05/2018 09:10:20 AM

Expected Output

23/05/2018 06:40:20 PM

Code

string time = con.PayloadsUl.Timestamp.ToString();
onem2m.time = Convert.ToDateTime(time).ToString(string.Format("dd/MM/yyyy hh:mm:ss tt"));

data type

public class onem2m {
    public string dataFrame{ get; set; }
    public string time { get; set; }
}
krishna mohan
  • 133
  • 1
  • 2
  • 11

2 Answers2

0

Something like this?

string time = con.PayloadsUl.Timestamp.ToString();
DateTime utcdate = DateTime.ParseExact(time, "M/dd/yyyy 
                                           h:mm:ss tt",CultureInfo.InvariantCulture);

    var istdate = TimeZoneInfo.ConvertTimeFromUtc(utcdate,
    TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
Immorality
  • 2,164
  • 2
  • 12
  • 24
-3

Try Using SimpleDateFormat class and

TimeZone.getTimeZone("IST")
Abdul Rahman
  • 1,891
  • 1
  • 9
  • 11
  • What `SimpleDateFormat`/`TimeZone` class? That does not exist on the .NET Framework. – Camilo Terevinto May 23 '18 at 12:19
  • 1
    @Camilo Seems to be a java answer to a C# question :-( – ProgrammingLlama May 23 '18 at 12:27
  • 1
    @john I imagined, but I don't know enough Java to point that out – Camilo Terevinto May 23 '18 at 12:28
  • 1
    Even if this were Java, use of the `SimpleDateFormat` class is strongly discouraged, that class is long outdated and notoriously troublesome. And you should never rely on a three letter time zone abbreviation like IST. You cannot know whether Java gives you Irish Summer Time, Israel Standard Time or India Standard Time. – Ole V.V. May 23 '18 at 13:17