datetime-format

Computing milliseconds since 1970 in C# yields different date than JavaScript

三世轮回 提交于 2020-01-02 02:19:22
问题 I need to compute the JavaScript getTime method in C#. For simplicity, I chose a fixed date in UTC and compared the C#: C# DateTime e = new DateTime(2011, 12, 31, 0, 0, 0, DateTimeKind.Utc); DateTime s = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan t = (e - s); var x = t.TotalMilliseconds.ToString(); => 1325289600000 and the JavaScript results: JavaScript var d = new Date(2011, 12, 31, 0, 0, 0) var utcDate = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d

Converting time to UTC time goes the opposite way

Deadly 提交于 2020-01-01 19:44:08
问题 I'm trying to parse an offset time using Java 8 DateTimeFormatter. I live in EST time which is UTC-5, so when I try to convert 2019-01-22T13:09:54.620-05:00 should be --> 2019-01-22T18:09:54.620 However, with my code, it gets the current time and goes back 5 hours, resulting in 2019-01-22 08:09:54.620 Code: import java.sql.Timestamp import java.time._ import java.time.format.DateTimeFormatter import scala.util.{Failure, Success, Try} class MyTimeFormatter(parser: DateTimeFormatter) { def

Converting time to UTC time goes the opposite way

独自空忆成欢 提交于 2020-01-01 19:44:07
问题 I'm trying to parse an offset time using Java 8 DateTimeFormatter. I live in EST time which is UTC-5, so when I try to convert 2019-01-22T13:09:54.620-05:00 should be --> 2019-01-22T18:09:54.620 However, with my code, it gets the current time and goes back 5 hours, resulting in 2019-01-22 08:09:54.620 Code: import java.sql.Timestamp import java.time._ import java.time.format.DateTimeFormatter import scala.util.{Failure, Success, Try} class MyTimeFormatter(parser: DateTimeFormatter) { def

How to determine what date time format the system is using?

微笑、不失礼 提交于 2019-12-31 04:20:11
问题 For my centralized logging purposes for an application that will be used over the network(no server side application involved, yet) I am required to also store the time at which a particular event occurs. The task is pretty much easy but the problem is, as I have noticed, the computers over the network don't have their time setup accurately. Therefore in order to standardize the time I choose to grab it from the NAS using net time \\nas. All's good to this point. Now the problem is, the

Java: How to convert string with month name to DateTime?

点点圈 提交于 2019-12-31 03:47:11
问题 I've seen answers that let me convert when the format is like "14/02/1952 14:52:22" by using DateTimeFormatter DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss"); DateTime dt = formatter.parseDateTime(string); How do I apply the same idea to strings of this format: "Sunday, September 29, 2013 7:59:58 AM PDT" I am trying DateTimeFormatter formatter = DateTimeFormat.forPattern"EEEE, MMMM dd, yyyy h:mm:ss a zzz"; DateTime dt = formatter.parseDateTime(string); but it's

Python - Getting the date format [duplicate]

半世苍凉 提交于 2019-12-30 10:57:10
问题 This question already has answers here : How to determine appropriate strftime format from a date string? (3 answers) Closed 2 years ago . I'm getting a date as a string, then I'm parsing it to datetime object. Is there any way to check what's is the date format of the object? Let's say that this is the object that I'm creating: modified_date = parser.parse("2015-09-01T12:34:15.601+03:00") How can i print or get the exact date format of this object, i need this in order to verify that it's in

Correct insert DateTime from c# to mongodb

半世苍凉 提交于 2019-12-30 01:22:08
问题 I try to insert local time in MongoDB var time = DateTime.Now; // 03.05.2014 18:30:30 var query = new QueryDocument { { "time", nowTime} }; collection3.Insert(query); But in database I see ISODate("2014-05-03T15:30:30.170Z") , that must be ISODate("2014-05-03T18:30:30.300Z") . Please help me! 回答1: I think you're getting confused by time zones. The Z at the end of the string indicates that it's in UTC. When you posted this question, it was just after 15:30 UTC. I strongly suspect that the

Correct insert DateTime from c# to mongodb

孤者浪人 提交于 2019-12-30 01:22:07
问题 I try to insert local time in MongoDB var time = DateTime.Now; // 03.05.2014 18:30:30 var query = new QueryDocument { { "time", nowTime} }; collection3.Insert(query); But in database I see ISODate("2014-05-03T15:30:30.170Z") , that must be ISODate("2014-05-03T18:30:30.300Z") . Please help me! 回答1: I think you're getting confused by time zones. The Z at the end of the string indicates that it's in UTC. When you posted this question, it was just after 15:30 UTC. I strongly suspect that the

Get original pattern String given a JDK 8 DateTimeFormatter?

旧街凉风 提交于 2019-12-28 03:04:28
问题 Related to my question here - how do I get the original pattern String given a DateTimeFormatter ? 回答1: It's been asked on the mailing list and the answer is that it is not possible because the original pattern is not retained. The same thread suggests using a DateTimeFormatterBuilder which does have the information. 回答2: It may not be a direct answer to your question but it may help. If you know the parameters of how it the formatter was constructed you can call the static method:

How do I get the AM/PM value from a DateTime?

我只是一个虾纸丫 提交于 2019-12-27 17:06:51
问题 The code in question is below: public static string ChangePersianDate(DateTime dateTime) { System.Globalization.GregorianCalendar PC = new System.Globalization.GregorianCalendar(); PC.CalendarType = System.Globalization.GregorianCalendarTypes.USEnglish; return PC.GetYear(dateTime).ToString() + "/" + PC.GetMonth(dateTime).ToString() + "/" + PC.GetDayOfMonth(dateTime).ToString() + "" + PC.GetHour(dateTime).ToString() + ":" + PC.GetMinute(dateTime).ToString() + ":" + PC.GetSecond(dateTime)