I feel I must have missed something but I just could not figure out how to create a UTC timestamp in MarkLogic using XQuery. The fn:current-dateTime function creates timestamp with timezone offset specified by the OS.
This is trivial using Server-side JavaScript:
new Date().toISOString()
// 2020-02-07T14:43:32.588Z
Thank you!
You can adjust timezone with the appropriate fn functions, like this:
fn:adjust-dateTime-to-timezone(fn:current-dateTime(), xs:dayTimeDuration("PT0H"))
HTH!
Related
I have a Cake\I18n\FrozenTime object that I need displayed both as 2020-09-11T04:15:44+00:00 and converted to a specific timezone.
Normally, I'd call ->format('c'), but that uses the UTC according to my app configuration.
I know I can convert to a timezone using ->i18nFormat('yyyy-MM-dd HH:mm', 'Europe/Copenhagen'), but then I'll lose the convenience of the c date format shorthand. IntlDateFormatter predefined constants are lacking, and those from DateTimeInterface, (specifically, \DateTime::ATOM) don't work.
So before I go ahead and reinvent the wheel with ->i18nFormat("yyyy-MM-dd'T'HH:mm:ssxxx", 'Europe/Copenhagen'), is there a better way to display a Cake\I18n\FrozenTime in a specific date format and a specific timezone?
If you want to keep a date object, you can simply apply the timezone conversion on the object.
Frozen* objects are immutable, so you'll end up with a new object when applying the conversion:
echo $obj->setTimezone('Europe/Copenhagen')->format('c')
See also
Chronos API > \Cake\Chronos\ChronosInterface::setTimezone()
In Flutter I need to parse and format date/time based on what my REST API passes back. The date/time format the server sends back is 2020-01-28T13:52:30.878+0000. In this example based on my locale it should be formatted as 8:52:30 AM EST. Does anyone know how I can achieve this using either a standard Dart package or some third-party package?
Just figured it out, using DateTime class there is a method toLocal() that does exactly what I need.
You can use DateTime.parse("2020-01-28T13:52:30.878+0000") to parse this format.
if GMT+5
formatedTime = DateTime.parse("2020-01-28T13:52:30.878+0000");
farmattedTime.add(Duration(hours: 5));
Is something wrong with code.
var mom = moment("23-11-2016 00:00", "DD-MM-YYYY HH:mm");
alert(mom.toISOString());
//result 2016-11-22T17:00:00.000Z
Why the result is not 2016-11-23T00:00:00.000Z? How I can get 2016-11-23T00:00:00.000Z result?
As the doc says:
By default, moment parses and displays in local time.
while .toISOString() always returns a timestamp in UTC:
Note that .toISOString() always returns a timestamp in UTC, even if the moment in question is in local mode. This is done to provide consistency with the specification for native JavaScript Date .toISOString(), as outlined in the ES2015 specification.
You probably have -7 hours offset from UTC.
Use format() if you want to display date in local time.
If your input string represents a UTC time, then use moment.utc(String, String);
I've been using toISOString to serialize momentJS date before sending to the server via jQuery. It works fine for me except it converts date to UTC but I need to keep the local timezone. Does momentJS have a method for this?
You can either call .format() without any parameters, or you can call .toISOString(true). Both are in ISO 8601 extended format, the difference is only in whether milliseconds are included or not.
// get the current moment, in local mode
const m = moment();
// format without parameters will give the ISO string including offset
console.log(`moment().format() === "${ m.format() }"`);
// if you want to include milliseconds, you can use toISOString(true) instead
console.log(`moment().toISOString(true) === "${ m.toISOString(true) }"`);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
Added in 2.20.0:
moment().toISOString(true)
Output:
"2018-05-13T16:16:13.507+03:00"
Found answer here.
Documentation.
please help me to find the best regex for the dateformat mm/dd/yyy and m/d/yyyy.
i have tried different links but everyone has some problems. so please help me to solve this.
What is the MM/DD/YYYY regular expression and how do I use it in php?
http://regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryId=5
http://www.regular-expressions.info/regexbuddy/datemmddyyyy.html
Use one of the DateTime.TryParse overloads (or DateTime.TryParseExact if you want more control) to validate whether a string is a valid representation of a DateTime.
DateTime dt;
if(DateTime.TryParse(someInputString, out dt)
{
// it is valid and dt can be used
}
This would be a better approach than regular expressions - it is faster, well tested and will produce a valid DateTime object.
If you need a regular expression then something like this would work (for most cases, since it allows 31st of February).
(0?\d|1[012])\/([012]?\d|3[01])\/\d{4}
Usually it is much better to use DateTime parsing for verifying date formats. Like DateTime.TryParseExact method. You can use the regular expression in the browser (in JavaScript) but you should really use DateTime parsing on the server side.