Skip to content

Instantly share code, notes, and snippets.

@anzfactory
Created August 30, 2019 14:03
Show Gist options
  • Save anzfactory/bb2a2d86b661240bc3b542e2a27467f3 to your computer and use it in GitHub Desktop.
Save anzfactory/bb2a2d86b661240bc3b542e2a27467f3 to your computer and use it in GitHub Desktop.
NCMBScriptをつかって現在日時を取得するサンプル
const moment = require('moment')
module.exports = function(req, res) {
const now = moment()
var json = {
date: now.format(),
formatted: req.query.format ? now.format(req.query.format) : null
}
res.json(json)
}
using NCMB;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web;
using UnityEngine;
public class ScriptRunner : MonoBehaviour
{
public void RunDateScript()
{
var script = new NCMBScript("date.js", NCMBScript.MethodType.GET);
Dictionary<string, object> query = null;
// フォーマットされたものが欲しい場合は query を渡す
query = new Dictionary<string, object>{
{"format", "YYYY/MM/DD"}
};
script.ExecuteAsync(header: null, body: null, query: query, callback: (byte[] result, NCMBException e) => {
if (e == null) {
var jsonString = Encoding.UTF8.GetString(result);
var info = JsonUtility.FromJson<DateInfo>(jsonString);
Debug.Log(info.date);
Debug.Log(DateTime.Parse(info.date));
Debug.Log(info.formatted);
} else {
Debug.LogError(e);
}
});
}
}
[System.Serializable]
public class DateInfo {
public string date;
public string formatted;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment