10 examples of 'date-fns utc' in JavaScript

Every line of 'date-fns utc' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
10function reformUTC (date, format) {
11 format = format || null;
12 var utc = date.toUTCString();
13 if (format === 'short') {
14 var arr = utc.split(' ');
15 var newArr = [];
16
17 for (var i = 0; i < 4; i++) {
18 newArr.push(arr[i]);
19 }
20
21 return newArr.join(' ');
22 }
23 return utc;
24}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

4function treatAsUtc(dateStr) {
5 let result = new Date(dateStr);
6 result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
7 return result;
8}
16function hackyTimeZone(dtf, date) {
17 var formatted = dtf.format(date).replace(/\u200E/g, '')
18 var tzNameMatch = / [\w-+ ]+$/.exec(formatted)
19 return tzNameMatch ? tzNameMatch[0].substr(1) : ''
20}
49function timeZoneGetter(date) {
50 var zone = -1 * date.getTimezoneOffset();
51 var paddedZone = (zone >= 0) ? "+" : "";
52
53 paddedZone += padNumber(Math[zone > 0 ? 'floor' : 'ceil'](zone / 60), 2) +
54 padNumber(Math.abs(zone % 60), 2);
55
56 return paddedZone;
57}
182private getDate (start: number, useUtc: boolean): Date {
183
184 // = 20150417
185
186 const n: number = this.buffer.getWholeNumber(start, start + 7)
187 if (n == null) {
188 return null
189 }
190 const monthDay: number = n % 10000
191 const month: number = Math.round(monthDay / 100)
192 const day: number = monthDay % 100
193 const year: number = Math.round(n / 10000)
194 let t: Date
195 if (useUtc) {
196 t = new Date(Date.UTC(year, month - 1, day, 0, 0, 0, 0))
197 } else {
198 t = new Date(year, month - 1, day, 0, 0, 0, 0)
199 if (this.adjustLocal) {
200 t = new Date(t.getTime() - t.getTimezoneOffset() * -60000)
201 }
202 }
203 return t
204}
95export function getUtcToSystem(dateObj: moment.MomentInput): Date {
96 // This is required because if your system timezone !== user configured timezone
97 // then there will be a mismatch of dates with `react-date-picker`
98 //
99 // We purposely strip the timezone when formatting from the utc timezone
100 return new Date(moment.utc(dateObj).format(DATE_FORMAT_NO_TIMEZONE));
101}
5export function dateUTCToLocal( date )
6{
7 return new Date( date.getTime( ) + TimeZoneOffset );
8}
149function SetUTCDate( t, date ) {
150 var T = t;
151 var DATE = Number( date );
152 var RESULT3 = MakeDay(YearFromTime(T), MonthFromTime(T), DATE );
153 return ( TimeClip(MakeDate(RESULT3, TimeWithinDay(t))) );
154}
3function utcdate(v, record){
4 return (Ext.Date.parseDate(v, 'c')).toUTC();
5}
53function utc() {
54 return new Date().getTime();
55}

Related snippets